Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code coverage / branch coverage recommended values

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?

like image 705
Matthias van der Vlies Avatar asked Dec 02 '11 15:12

Matthias van der Vlies


2 Answers

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)?

like image 91
Ilia Avatar answered Oct 04 '22 02:10

Ilia


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.

like image 24
Sergey Kalinichenko Avatar answered Oct 04 '22 04:10

Sergey Kalinichenko