0

我有一个单元测试类:

[TestFixture]
public class SomeClassIntegrationTests : SomeClass

使用公共构造函数:

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

当我尝试运行测试时,出现“未找到合适的构造函数”错误。

我尝试将TestFixture属性更改为,[TestFixture(typeof(ILogger))]但它导致相同的错误消息不允许我运行或调试测试。

知道如何修改TestFixture属性以使测试运行或以其他方式解决此问题吗?

4

1 回答 1

2

您可能需要一个实现 ILogger 的类的实例。

选项 1:使用 null (如果不需要记录器):

[TestFixture(null)]

选项 2:始终使用相同的具体类(或模拟):添加无参数构造函数

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

[TestFixture]

选项 3:您可能希望使用不同的记录器进行测试

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

[TestFixture(typeof(MyLogger))]
于 2018-11-20T18:44:16.390 回答