Hi, I have methods with more than one parameter that are guarded against bad input by throwing ArgumentNullExceptions and ArgumentExceptions whenever any parameter is null.
So there are two obvious ways to test this:
- One test per Parameter using the [ExpectedException] attribute
- One test for all parameters using multiple try{} catch blocks
The try catch thing would look like that:
try
{
controller.Foo(null, new SecondParameter());
Assert.Fail("ArgumentNullException wasn't thrown");
} catch (ArgumentNullException)
{}
With one little problem. If the test passes, Assert.Fail never gets called and will therefore be highlighted as not covered test code (by NCover).
I know this isn't actually a problem, since it's the business code I want 100% coverage of, not the test code. Still I am curious if there is a way to compress multiple Exception throwing calls into one Testcase without having dead LoCs?