Missing code coverage for closing brace after code throwing an exception

Viewed 924

In Visual Studio 2017 a closing brace after a statement that is throwing an exception is considered uncovered.

In my case I have a test checking if a NullReferenceException is thrown:

[Fact]
public void PassingNullConsoleWriter_ThrowsArgumentNullException()
{
    Assert.Throws<ArgumentNullException>(() => new UsagePrinter(null));
}

Analyzing code coverage in this form of the code marks the whole body of the lambda as uncovered, what obviously is not true:

Code Coverage marks body of lambda uncovered

Expanding the lambda to a statement lambda uncovers that actually it is the closing brace after the statement throwing the exception that is considered uncovered:

Code Coverage marks the closing brace uncovered

Note that the overall coverage of the file in both cases is the same.

Is there anything I can do about this?

1 Answers
Related