Does Nunit TestCase attribute with Result property work incorrect?
Asked Answered
P

1

2

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);
    }
Putman answered 11/2, 2012 at 15:10 Comment(0)
T
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.

Tantalus answered 14/2, 2012 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.