我有一个单元测试类:
[TestFixture]
public class SomeClassIntegrationTests : SomeClass
带公共构造函数:
public SomeClassIntegrationTests (ILogger l) : base(l)
{
}
当我尝试运行测试时,我得到了"没有找到合适的构造函数"的错误。
我尝试将TestFixture
属性更改为[TestFixture(typeof(ILogger))]
,但它导致了相同的错误消息,不允许我运行或调试测试。
知道如何修改TestFixture
属性以运行测试或以其他方式解决此问题吗?
您可能需要一个实现ILogger的类的实例。
选项1:使用null(如果记录器不是真正需要的(:
[TestFixture(null)]
选项2:始终使用相同的具体类(或mock(:添加无参数构造函数
SomeClassIntegrationTests()
: this(new MyLogger())
{
}
和
[TestFixture]
选项3:你可能想用不同的记录器进行测试
SomeClassIntegrationTests(Type t)
: this((Ilogger)Activator.CreateInstance(t))
{
}
和
[TestFixture(typeof(MyLogger))]