0

I’m trying to test out NUnit by running a few unit tests. However, I noticed one thing. In NUnit version 2.6.2 (the latest version), when I imported the test dll file, the tests passed and failed in the appropriate places and they gave me the correct warnings, messages and indicators.

However, in NUnit version 2.4 RC1, the same unit tests are ignored. The error message reads: “TestClass does not have any tests” but it does contain tests.

Why is this? I'm trying to validate the older version of the software and I need to run the unit tests on the older version.

I used this example to run the tests: http://www.codeproject.com/Articles/178635/Unit-Testing-Using-NUnit

3
  • Can you provide a code snippet with any of your tests? As simple as possible...
    – HuorSwords
    Commented Jul 25, 2013 at 16:16
  • Have a look at your references in the two test projects is my only guess Commented Jul 25, 2013 at 16:18
  • @HuorSwords, the code snippets and all the source code is available to download for free on CodeProject: codeproject.com/Articles/178635/Unit-Testing-Using-NUnit Scroll down to see snippets for Testing.
    – Kala J
    Commented Jul 25, 2013 at 16:20

1 Answer 1

6

If you had copied the snippet code from the referenced url, you must have something like this:

[TestFixture]
public class TestClass
{
    [TestCase]
    public void AddTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Add(20, 10);
        Assert.AreEqual(30, result);
    }

    [TestCase]
    public void SubtractTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Subtract(20, 10);
        Assert.AreEqual(10, result);
    }
}

But, if you check the documentation for the NUnit version 2.4 (here), you can see that the Property method that indicates a test is not [TestCase]. Use [Test] instead.

[TestFixture]
public class TestClass
{
    [Test]
    public void AddTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Add(20, 10);
        Assert.AreEqual(30, result);
    }

    [Test]
    public void SubtractTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Subtract(20, 10);
        Assert.AreEqual(10, result);
    }
}
2
  • Ohh I see. I'll double check it now.
    – Kala J
    Commented Jul 25, 2013 at 16:23
  • Yup, I got it working after I built the changes and then saved them. Thank you :D
    – Kala J
    Commented Jul 25, 2013 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.