Daily Usage Issues

Coverage issue with lambdas / xUnit?

Started by nuggetboy on 6,266 views

I noticed that the last line of xUnit Assert.Throws lambdas are being detected as untested:
[img=http://i.imgur.com/5rnEEF2.png]No coverage on last line of lambda[/img]

I can work around this by pulling up the last line with brace and parens like so:
[img=http://i.imgur.com/mPOiIe1.png]Workaround[/img]

But that seems dumb. Am I doing something wrong here? It seems like this should either be detected as covered or excluded from coverage.
Hi, thanks for posting.

This line is marked as not covered by NCrunch - because it is physically not being executed at runtime.

When SomeException is thrown, the exception bubbles up the call stack and any code after it is inside the scope is not executed. You'll notice that if you put a breakpoint on this line of code, it will never be touched.

There is no way for NCrunch to exclude such a line of code automatically without attempting to read into your code to understand what it does. Rather than try to make guesses about the intention of the code based on how it is structured, NCrunch simply displays the behaviour as it physically is.

If this is making a mess of your metrics, I'd suggest excluding it from the metrics calculation by marking it with //ncrunch: no coverage
Got it! I'll use the "//ncrunch: no coverage" tip you gave.

Thanks for the reply, Remco.

Post a reply

Log in to reply.