Does Nunit TestCase attribute with Result property work incorrect?

女生的网名这么多〃 提交于 2019-12-11 03:22:14

问题


So, I wrote next "test" test :-) for Nunit 2.6 (use 2.6.0.12035 ver.)

    [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;
    }

Next, I run it with Resharper 6.1.37.86. Resharper shows that all three test are passed. Than I try to run test with nunit GUI - nunit.exe. Tests fall with strange error message: "Method has non-void return value". In fact all tests should fail with unexpected value of result. Does this feature work incorrect or I do smth. wrong? By the way, next I try do without set Result property and it works perfect with both runners:

    [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);
    }

回答1:


I get the same problem with NUnit 2.6.0.12035, whether I use NUnit.exe or NUnit-console.exe.

Your example works fine using NUnit.exe 2.5.10. (My guess is that Resharper is using NUnit 2.5.10 and so the test passes.)

I reported the issue to the NUnit discussion group.

Edit: My test assembly was referencing the 2.5.10 version of NUnit.framework.dll. If I switch to use the 2.6.0.12035 version, the test works as expected with both NUnit.exe and NUnit-console.exe. I'll bet your issue is the same.

Edit 2: It has been submitted as a bug and fixed in the next release. The test runners in 2.6 will no longer cause an error if your unit test library links to an older version of Nunit.framework.dll.



来源:https://stackoverflow.com/questions/9241232/does-nunit-testcase-attribute-with-result-property-work-incorrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!