c# - 从 AutoFixture/AutoMaq 请求模拟时,NUnit 会忽略测试

标签 c# unit-testing nunit autofixture automoq

我将 NUnitAutoFixtureAutoMoqTheory 属性结合使用。

这是我的测试方法,

[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/

相关文章:

c# - MSCRM 站点地图链接到 .htm 页面。如何传递参数?

c# - 了解 OpacityMask 的有效区域

jquery - 如何对 ASP.Net MVC JsonResult 操作进行单元测试?

使用 get/set 的 C# 线程安全

C# - 二进制搜索(排序)字典

c++ - CppUnitTestFramework 和测试 "vector subscript out of range"

unit-testing - 仅在测试环境上运行迁移脚本

ios - 单元测试 iOS 中的子模块静态函数? ( swift 4 - Xcode)

c# - NUnit RemoteTestRunner 不会加载 app.config

batch-file - 批处理窗口命令行不能与 Jenkins 一起使用,而可以手动工作