question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line coverage fails for closing brace in tests expecting exceptions

See original GitHub issue

For a test like:

[TestMethod]
[ExpectedException(typeof(Exception))]
public void SomeTest()
{
   ThrowsException();
} // Coverage fails for this line

AxoCover will show that the closing brace is not covered (as the comment shows).

Although it is technically correct (the line will never be reached for any successful test), I would like to, at least, be able to indicate that coverage for this line should be ignored as I am targeting a 100% coverage.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
axodoxcommented, Apr 30, 2017

To be honest I agree with the current result, but for sure you should report this on the OpenCover project’s issue board as AxoCover displays OpenCover results.

Also some testing tips:

  • You should check the coverage of the application under test, not your test code. The coverage of the tests by themselves is not really relevant in most cases - well if you really have much test code which never runs, then you might need to refactor something.
  • Generally you should not aim to have 100% coverage as in most cases that has marginal benefit over let’s say 70% or 85% coverage.
  • It is more important to make your tests are really doing their job, e.g. if you change what your code does in a significant way, they fail - so you be sure they prevent regressions. See mutation testing.
0reactions
sawildecommented, Jan 3, 2019

Ah well - it seems the sequence point for the line also encapsulates the end brace

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Missing code coverage for closing brace after ...
In Visual Studio 2017 a closing brace after a statement that is throwing an exception is considered uncovered. In my case I have...
Read more >
Code coverage colouring is red highlighting a test method ...
This is by design. Once the exception is thrown, the control moves to catch, & the closing braces "}" is never hit, which...
Read more >
How do I increase my code coverage, or why can't I cover ...
Code coverage is a measurement of how many unique lines of your code are executed while the automated tests are running.
Read more >
Closing brace reported as not covered by tests
When testing the following block of code, NCrunch reports all code as covered by tests except the closing braces of the "if" blocks....
Read more >
Closing bracket after method that always throws exception
I have implemented test for each check, but code is not covered for 100%. dotCover marked closing curly brace after each RaiseError call...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found