Say I have the following:
[Test]
// would like to parameterize the parameters in call AND the call itself
public void Test()
{
var res1 = _sut.Method1(1);
var res2 = _sut.Method2("test");
var res3 = _sit.Method3(3);
Assert.That(res1, Is.Null);
Assert.That(res2, Is.Null);
Assert.That(res3, Is.Null);
}
I’d like to parameterize the tests using the TestCase/TestCaseSource attribute including the call itself. Due to the repetitive nature of the tests, each method needs to be called with slightly different parameters, but I need to be able to tag a different call for each of the different parameters. Is this even possible in Nunit? If so, how would I go about it?
Using TestCaseSource, you should be able to loop over an array of values and invoke the desired methods, for example like this:
Note that the
_sutinstance needs to be instantiated in theTestClassconstructor. It is not sufficient to initialize it within a[SetUp]or[TestFixtureSetUp]method.In case you need different
_sutinstantiations for different method invocations, you could create a collection ofSutinstances in the constructor, and access the relevantSutitem within theforloop of theTestCasesgetter. Alternatively, you could even loop over allSutitems in the getter…