Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run individual parameterized testcase with nunit-console

Tags:

c#

nunit

I can run an individual testcase which takes a single string value with no problems from the command line:

For example /run:Namespace.Class.Method("my input string")

However the same procedure doesn't seem to work for me with numerical inputs

For example: /run:Namespace.Class.Method(1,2,3)

The output lists the correct input as a 'test to run' but does not actually run any tests

EDIT:

Looking into this further, it appears that the problem is with tests which take more than one argument. Using the following test file:

namespace GetTestsProj
{
    [TestFixture]
    class NunitConsoleTest
    {
        [TestCase(1,2,3)]
        [Test, Description("A simple test with parameterized numeric inputs")]
        public void TestNumeric(int a, int b, int c)
        {
            Assert.AreEqual(c, a + b);
        }

        [TestCase("My String")]
        [Test, Description("A simple test with parameterized string input")]
        public void TestSingleString(string a)
        {
            Assert.AreEqual("My String", a);
        }
        [TestCase("String1", "String2")]
        [Test, Description("A simple test with parameterized numeric inputs")]
        public void TestTwoStrings(string a, string b)
        {
            Assert.AreEqual("String1", a);
        }
    }
}

The call nunit-console.exe /run:GetTestsProj.NunitConsoleTest GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll properly runs all 3 testcases

The call nunit-console.exe /run:GetTestsProj.NunitConsoleTest.TestNumeric GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll properly runs 1 testcase

The call nunit-console.exe /run:"GetTestsProj.NunitConsoleTest.TestSingleString(\"My String\")" GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll properly runs 1 testcase

However, the call nunit-console.exe /run:GetTestsProj.NunitConsoleTest.TestNumeric(1,2,3) GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll runs 0 testcases

And similarly the call nunit-console.exe /run:"GetTestsProj.NunitConsoleTest.TestTwoStrings(\"String1\",\"String2\")" GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll runs 0 testcases

Although nunit seems to recognize the input /run properly:

Selected test(s): GetTestsProj.NunitConsoleTest.TestNumeric(1,2,3)

Tests run: 0, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

and

Selected test(s): GetTestsProj.NunitConsoleTest.TestTwoStrings("String1", "String2")

Tests run: 0, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0156256 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

This is all using NUnit 2.5.9.10348

I'm interested in whether this is user error or unsupported functionality. It would be very useful for what I am trying to do.

like image 822
afranz409 Avatar asked Mar 02 '11 17:03

afranz409


1 Answers

It looks like the problem is that the list of testcases is split on the ',' character, causing an obvious problem for parameterized testcases. Bug information is here, and I'll try to post the conclusion on here when there is more information.

like image 172
afranz409 Avatar answered Dec 02 '22 11:12

afranz409