Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using category expressions in Nunit console runner

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.

like image 823
Kala J Avatar asked Aug 13 '13 14:08

Kala J


People also ask

What is console in NUnit 3?

Console Runner The nunit3-console.exe program is a text-based runner for listing and running our tests from the command-line. It is able to run all NUnit 3.0 or higher tests natively and can run NUnit 2.x tests if the v2 driver is installed. This runner is useful for automation of tests and integration into other systems.

What is the use of NUnit runner?

It is able to run all NUnit 3.0 or higher tests natively and can run NUnit 2.x tests if the v2 driver is installed. This runner is useful for automation of tests and integration into other systems. It automatically saves its results in XML format, allowing you to produce reports or otherwise process the results.

What is the purpose of using categories in NUnit tests?

When categories are used, only the tests in the selected categories will be run. Those tests in categories that are not selected are not reported at all. While the C# syntax allows you to place a Category attribute on a SetUpFixture class, the attribute is ignored by NUnit and has no effect in current releases.

What does nunit3-console show when running tests?

In this example, nunit3-console has just run selected tests in the mock-nunit-assembly.exe assembly that is part of the NUnit distribution. This assembly contains a number of tests, some of which are either ignored or marked explicit. The summary line shows the result of the test run.


1 Answers

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"
like image 146
Kala J Avatar answered Oct 02 '22 02:10

Kala J