Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not all tests are run in parameterised NUnit TestFixture containing arrays

I have a test class as follows:

[TestFixture("someurl1", new[] { "param1", "param2" }, 15)]
[TestFixture("someurl2", new[] { "param3" }, 15)]
public class my_test
{
    public my_test(string url, string[] fields, int someVal)
    {
        // test setup
    }
}

When running this test in ReSharper 6.1 and NUnit 2.5.10, the test is not run twice, as expected, it only runs once. In the test results I see listed

my_test("someurl1", System.String[], 15)

This makes me think that the two fixtures are being treated as the same, and that NUnit isn't differentiating between the string arrays in the two tests.

As a workaround I have added a dummy parameter in the constructor. If I set this to a different value for each fixture, then all the tests run.

Is it not possible to have TestFixtures with arrays containing different values? I've just upgraded from ReSharper 5 so I'm wondering if that is related. I have read about some issues with parameterised tests in 6.x.

like image 950
Chris Wignall Avatar asked Apr 05 '12 13:04

Chris Wignall


People also ask

What is TestFixture attribute used in NUnit?

The [TestFixture] attribute at the beginning indicates that this class is a test fixture so that NUnit can identify it as a runnable test class. Similarly NUnit uses attributes to indicate various properties of classes/methods. Then you see two methods tagged [SetUp] and [TearDown].

How do you write multiple test cases in NUnit?

Make more copies of the attribute if you want multiple cases. The data type of the values provided to the TestCase attribute should match with that of the arguments used in the actual test case.

What is OneTimeSetUp in NUnit?

This attribute is to identify methods that are called once prior to executing any of the tests in a fixture. It may appear on methods of a TestFixture or a SetUpFixture. OneTimeSetUp methods may be either static or instance methods and you may define more than one of them in a fixture.

Which attribute is used to mark the test class in the NUnit?

The Test attribute is one way of marking a method inside a TestFixture class as a test.


1 Answers

[TestFixture("someurl1", "param1|param2", 15)]
[TestFixture("someurl2", "param3", 15)]
public class my_test
{
    private string[] _fields;

    public my_test(string url, string fieldList, int someVal)
    {
        _fields = fieldList.Split('|');
        // test setup
    }

    [Test]
    public void listFields()
    {
        foreach (var field in _fields)
        {
            Console.WriteLine(field);
        }
    }
}
like image 99
mrtgold Avatar answered Oct 02 '22 03:10

mrtgold