我将 NUnit
与 AutoFixture
、AutoMoq
和 Theory
属性结合使用。
这是我的测试方法,
[TestFixture]
public class TestClass
{
[Theory, AutoMoqData]
public void TestI(I i)
{ }
}
界面
public interface I
{ }
和属性
public class AutoMoqDataAttribute : AutoDataAttribute
{
public AutoMoqDataAttribute()
: base(new Fixture().Customize(new AutoMoqCustomization()))
{ }
}
当我构建解决方案时,测试被发现。当我运行测试时,以下内容将写入输出窗口:
NUnit 1.0.0.0 executing tests is started
Run started: [...].Test.dll
NUnit 1.0.0.0 executing tests is finished
Test adapter sent back a result for an unknown test case. Ignoring result for 'TestI(Mock<TestClass+I:1393>.Object)'.
当使用xUnit.net
时,上述测试可以正确运行。为什么它不能与 NUnit
一起使用?
我在测试项目中安装了以下 Nuget 包:
- 自动夹具3.18.1
- AutoFixture.AutoMoq 3.18.1
- 起订量 4.2.1402.2112
- NUnit 2.6.3
- NUnitTestAdapter 1.0
我正在 Visual Studio 2013 Professional 中运行测试。我还尝试在单独的 GUI 运行器中运行测试,得到相同的结果。
最佳答案
以下 NUnit 测试在 Visual Studio 2013 中通过 TestDriven.Net插件:
internal class AutoMoqDataAttribute : AutoDataAttribute
{
internal AutoMoqDataAttribute()
: base(
new Fixture().Customize(
new AutoMoqCustomization()))
{
}
}
public interface IInterface
{
}
public class Tests
{
[Test, AutoMoqData]
public void IntroductoryTest(IInterface i)
{
Assert.NotNull(i);
}
}
内置测试运行程序不会发现上述测试。这看起来像是测试运行程序中的错误。
关于c# - 从 AutoFixture/AutoMaq 请求模拟时,NUnit 会忽略测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22882992/