7

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.

4
  • Does it work in the NUnit runner? Commented Apr 5, 2012 at 14:27
  • Also, thanks for pointing out that you can have parameterised test fixtures, as I didn't know this was possible. Commented Apr 5, 2012 at 14:30
  • 1
    Just tried in the NUnit runner and that runs all the tests successfully. I think it could be related to the ReSharper upgrade. Commented Apr 5, 2012 at 14:59
  • 1
    I've had problems before with resharper's runner. I just stick to the NUnit one now. Commented Apr 5, 2012 at 15:00

4 Answers 4

4
[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);
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

I think this is related to newing-up an array in the TestFixture constructor, I read somewhere that you can't do that.

Comments

0

Have you tried creating individual tests under it as a generic TestFixture??? Something like

[TestFixture]
public class my_test
{
    private bool my_test(string url, string[] fields, int someVal)
    {
        // test setup
        return DidTestCompleteOk;
    }

    [Test]
    public void TestURL1()
    {
        Assert.IsTrue( my_test("someurl1", new[] { "param1", "param2" }, 15));
    }

    [Test]
    public void TestURL2()
    {
        Assert.IsTrue( my_test("someurl2", new[] { "param3" }, 15) );
    }
}

Comments

0

It turns out this is the absolute error message if ANYTHING goes wrong in a parameterized test fixture's constructor. You don't get the actual exception information returned like when stuff fails in other code.

So you probably should move your setup code to a [SetUp] or [TestFixtureSetUp] or reallly be sure your constructor is executing without error. But really you should be doing the first suggestion, and only save the test fixture parameters in the constructor and do something with them in another method.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.