Coverage of trailing End If/End Try Statements
Coverage of trailing End If/End Try Statements
I have started using NCover with NUnit to develop and unit tests for some of my personal apps. Getting 100% coverage on modules is convenient, because it tells me at a glance I haven't missed anything too obvious. I've noticed 2 cases where I don't seem to get 100% coverage, but all 'real' executable lines execute.
One case is:
Public Function Test(Value as Boolean) as Boolean
If Value Then
Return True
Else
Return False
End If
End Function
From what I can see, the 'End If' is always tagged as not executed and you cannot get 100% coverage of this code. You could rewrite it to something logically equivalent such as the following to get 100% coverage:
Public Function Test(Value as Boolean) as Boolean
If Value Then
Return True
End If
Return False
End Function
A similar case exists with Try/Catch, but I haven't found a solution for that one yet to get 100%.
Is this design-intent for NCover? Is this good coding practice, or is there a reason not to write the code as above? I know if I put the first example in Eclipse in Java I get a compiler warning, but I don't understand why.
Any help appreciated,
Geoff Hart