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.
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].
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.
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.
The Test attribute is one way of marking a method inside a TestFixture class as a test.
[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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With