【问题标题】:Does Nunit TestCase attribute with Result property work incorrect?具有 Result 属性的 Nunit TestCase 属性是否工作不正确?
【发布时间】:2012-03-03 17:11:31
【问题描述】:

所以,我为 Nunit 2.6 编写了下一个“测试”测试 :-)(使用 2.6.0.12035 版本)

    [TestCase(1, 2, Result = 3)]
    [TestCase(3, 4, Result = 7)]
    [TestCase(5, 6, Result = 11)]
    public int Add_Test(int a, int b)
    {
        return a - b;
    }

接下来,我使用 Resharper 6.1.37.86 运行它。 Resharper 显示所有三个测试都通过了。 比我尝试使用 nunit GUI - nunit.exe 运行测试。测试出现奇怪的错误消息:“方法具有非空返回值”。 事实上,所有测试都应该以意想不到的结果值失败。 这个功能是否工作不正确或者我做了什么。错误的? 顺便说一句,接下来我尝试不设置 Result 属性,它适用于两个跑步者:

    [TestCase(1, 2, 3)]
    [TestCase(3, 4, 7)]
    [TestCase(5, 6, 11)]
    public void Add_Test1(int a, int b, int result)
    {
        Assert.AreEqual(result, a - b);
    }

【问题讨论】:

    标签: nunit resharper resharper-6.0


    【解决方案1】:

    无论我使用 NUnit.exe 还是 NUnit-console.exe,我都遇到了与 NUnit 2.6.0.12035 相同的问题。

    您的示例使用 NUnit.exe 2.5.10 可以正常工作。 (我的猜测是 Resharper 使用的是 NUnit 2.5.10,所以测试通过了。)

    我 reported the issue NUnit 讨论组。

    编辑:我的测试程序集引用了 NUnit.framework.dll 的 2.5.10 版本。如果我切换到使用 2.6.0.12035 版本,则 NUnit.exe 和 NUnit-console.exe 的测试都可以正常工作。我敢打赌你的问题是一样的。

    编辑 2: 它已作为错误和fixed in the next release 提交。如果您的单元测试库链接到旧版本的 Nunit.framework.dll,2.6 中的测试运行程序将不再导致错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      相关资源
      最近更新 更多