簡體   English   中英

解決NUnit“找不到合適的構造函數”消息

[英]Resolving NUnit “No suitable constructor was found” message

我有一個單元測試課:

[TestFixture]
public class SomeClassIntegrationTests : SomeClass

使用公共構造函數:

public SomeClassIntegrationTests (ILogger l) : base(l)
{
}

當我嘗試運行測試時,出現“找不到合適的構造函數”錯誤。

我嘗試將TestFixture屬性更改為[TestFixture(typeof(ILogger))]但它導致出現相同的錯誤消息,不允許我運行或調試測試。

是否知道如何修改TestFixture屬性以使測試運行或以其他方式解決此問題?

您可能需要一個實現ILogger的類的實例。

選項1:使用null(如果確實不需要記錄器):

[TestFixture(null)]

選項2:始終使用相同的具體類(或模擬):添加無參數構造函數

SomeClassIntegrationTests()
: this(new MyLogger())
{
}

[TestFixture]

選項3:您可能想用其他記錄器進行測試

SomeClassIntegrationTests(Type t)
: this((Ilogger)Activator.CreateInstance(t))
{
}

[TestFixture(typeof(MyLogger))]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM