I am using NUnit 2.5, and I want to test a method that recieves several parameters.
Is it reasonable to try to test them using one Test method, with several different TestCases, or will it be harder to maintain (Or just pin point the exact failure) in the long run?
My general idea is to try something like
[TestCase("valid", Result="validasd",
Description = "Valid string test, expecting valid answer")]
[TestCase(null, ExpectedException = typeof(ArgumentNullException),
Description = "Calling with null, expecting exception")]
[TestCase("", ExpectedException = typeof(ArgumentException),
Description = "Calling with an empty string, expecting exception")]
public string TestSubString(string value)
{
return MethodUnderTest(value);
}
Is it also a recommended usage – without an explicit assert, just checking on the return value? Or should I stick to the normal way or asserting the value inside the method?
I have found the TestCase attribute to be useful when testing methods that primarily accept some simple values, compute with them, and then return a result. In these cases, it takes substantially less overhead and duplication to write such tests.
This approach does not work when the method requires complex object parameters, because the TestCase attribute can only accept primitive types as input parameters to pass to the method.
You may also want to consider writing a more typical unit test if: