[TestMethod, ExpectedException(typeof(InvalidOperationException)]
public void InvalidOperaionTest()
{
MethodUnderTest(); // should throw the exception in the current state
// lines after that point can not be reached on a successfull test
// with the current behaviour of NCrunch this line would be marked as uncovered
// something like the following should suppress this:
// ncrunch: no coverage next
}
It looks like this is negligible because per such a test there is only one line of uncovered code, but source files wich are not at 100% coverage make me recheck them ever and ever again.
I'm aware that I could write my test like that:
[TestMethod]
public void InvalidOperaionTest()
{
InvalidOperationException expectedException = null;
try
{
MethodUnderTest(); // should throw the exception in the current state
This is about unit tests in the form:
[TestMethod, ExpectedException(typeof(InvalidOperationException)]
public void InvalidOperaionTest()
{
MethodUnderTest(); // should throw the exception in the current state
// lines after that point can not be reached on a successfull test
// with the current behaviour of NCrunch this line would be marked as uncovered
// something like the following should suppress this:
// ncrunch: no coverage next
}
It looks like this is negligible because per such a test there is only one line of uncovered code, but source files wich are not at 100% coverage make me recheck them ever and ever again.
I'm aware that I could write my test like that:
[TestMethod]
public void InvalidOperaionTest()
{
InvalidOperationException expectedException = null;
try
{
MethodUnderTest(); // should throw the exception in the current state
} // ncrunch: no coverage
catch(InvalidOperationException ex)
{
expectedException = ex;
}
Assert.IsNotNull(expectedException);
}
but this looks very bloated to me.