Code coverage / branch coverage recommended values
Asked Answered
T

3

6

I'm using Cobertura to calculate code/branch coverage for a Java project with JUnit test cases. I know 100% coverage does not tell how good the code is, but at the moment it's 6%. Branch coverage is 1%. My intuition says branch coverage is probably more important, due to the decision making nature of this project. As this is my only big project at the moment I have no experience in proper values for code/branch coverage aims.

I believe branch coverage is very important in this application, so I set the required value to 100%. I've defined the code coverage threshold to 80%.

Also what factor does code complexity for these values?

I am probably emphasising too much on numbers, but I'd like to hear about experience from other people. I'm aware these values are dependant on the project nature, but are there some general pointers/articles/personal experience I can refer to?

Talkingto answered 2/12, 2011 at 15:32 Comment(0)
P
5

When I measured branch coverage produced by manual tests used for functional testing I got ~65%

Also look at What is a reasonable code coverage % for unit tests (and why)?

Philipson answered 3/12, 2011 at 5:32 Comment(0)
J
4

I'd like to hear about experience from other people.

I wrote a library with several thousands lines of code, and a coverage suite that was longer than the library itself. At 99.98%, I covered every single line except one: the method came from a legacy project, and I did not know how to construct a test case that would hit that line. When my library went into production, the very first bug report was caused by that single untested line.

My take-home lesson from that project was that the lines you don't know how to hit are the most dangerous. If your project is decision-intensive, it's in your best interest to get 100% coverage.

Judsen answered 2/12, 2011 at 15:46 Comment(1)
even 100% of line coverage cannot guarantee a bug free software. Even 100% of branching coverage cannot guarantee that also.Trident
S
0

In most companies where I've worked we don't enforce branch coverage at all. In one of the companies there was a branch coverage of 1.0 and I can tell you that it's time consuming and useless. You almost double your development time and end up with a huge codebase full of useless tests. Also, engineers generally don't like writing tests that cover all branches cause it's boring.

As for line coverage, a value of 0.7 works well since it forces the engineer to cover most of the code that's written. Most companies where I've worked don't enforce testing coverage at all though and that's also my preferred style. Engineers are smart enough to write useful tests without enforcement.

Suit answered 9/8, 2021 at 7:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.