I have a couple of unit test helper extension methods, such as, IsNotEmpty(this string str)
for which I have also written unit tests. The basic structure of these tests is that I have one test that verifies that the extension method passes and returns the expected result on a "good" input, and one that verifies that a fail exception is thrown on "bad" input. For example, the fail tests for the above method might look like this:
[TestMethod, Fails]
public void IsNotEmpty_Fails_On_Empty_String()
{
"".IsNotEmpty();
}
where Fails
is an attribute I wrote myself - basically a proxy for [ExpectedException(typeof(AssertFailedException))]
. So I'm explicitly expecting an exception to be thrown on the only line in the above test, and thus, I'm not expecting the method to run all the way.
But when I right-click my solution, select "Test with->NCover", I get less than 100% code coverage* on all methods like the above one, with the ending brace highlighted red.
Why does NCover complain about my test method not finishing, when I've said that it won't?
*) For all those of you who will reply that 100% code coverage is not necessary: No, I'm not particularily worried about maintaining a 100% code coverage at all costs. However, in these cases methods that do matter show up as not covered in the list, and I have to go all the way into the tree to see that it's just them. That's the issue I'm trying to get at here - not 100% code coverage in general.