7

I was reading through this link on category expressions when using /include or /exclude statement. I want to be able to include only run test to be run out of two tests available or run all tests but using the /include:A+B or /exclude:A. However, for some reason, it displays the wrong number of tests to be run and/or not run. Why is that?

Can anyone provide me with an example on how to category expressions (by manipulating source code) and add how to run the command in the console?

Essentially what I did was:

using System;
using NUnit;
using NUnit_Application;
using NUnit.Framework;

namespace NUnit_Application.Test
{
[TestFixture]
[Category("MathS")] 
public class TestClass
{
    [TestCase]
    [Category("MathA")]
    public void AddTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Add(20, 10);
        Assert.AreEqual(40, result);
    }

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

And my command line statement was nunit-console /framework:net-4.0 /run:NUnit_Application.Test.TestClass.AddTest C:~\NUnit_Application\NUnit_Application\NUnit_Application.Test\bin\Debug\NUnit_Application.Test.dll /include:"MathA"

The thing is, the console is familiar with what the commands means and it says it included Math A category. However, it shows that zero tests have ran and zero tests have not run.

I'm running NUnit 2.6.2, the console runner.

Kala J
  • 2,040
  • 4
  • 45
  • 85

2 Answers2

2

Here is command I used initially:

nunit-console /framework:net-4.0 /run:NUnit_Application.Test.TestClass.AddTest C:~\NUnit_Application\NUnit_Application\NUnit_Application.Test\bin\Debug\NUnit_Application.Test.dll /include:"MathA"

I noticed if I just call TestClass and not the individual test case, it works:

nunit-console /framework:net-4.0 /run:NUnit_Application.Test.TestClass C:~\NUnit_Application\NUnit_Application\NUnit_Application.Test\bin\Debug\NUnit_Application.Test.dll /include:"MathA"
Kala J
  • 2,040
  • 4
  • 45
  • 85
0

I think it's because you have the whole class with the attribute :

[Category("MathS")]

So it skips over it.

will
  • 121
  • 1
  • 1
  • 9
  • I removed [Category("MathS")] but I still have the same problem. – Kala J Aug 13 '13 at 14:53
  • Yes, I did recompile. Maybe give me an example? I just want to test out the features of NUnit and learn how to use it for category expressions. – Kala J Aug 13 '13 at 15:12
  • I got it to work. The only strange thing is why when I include:MathA+MathB, none of the tests run. But if I exclude:MathA+MathB, it says 2 tests ran. Why is that? – Kala J Aug 13 '13 at 17:30
  • 1
    Per the NUnit docs (your link), `MathA+MathB` means *both* categories -- i.e. a test has to be in both categories to be included or excluded. I think what you want is `/include:MathA,MathB` which should run tests that are in *either* (or both) of the two categories. – David Aug 13 '13 at 19:09