Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure Code Coverage only on New Code

We are looking for a creative way to measure code coverage on new code separate from existing code. We have a large legacy project and want to start getting 90+% coverage on any new functionality. We would like a way to easily view a report that filters out any older code to make sure the new functionality is meeting our goal. Obviously still looking a increasing overall coverage on the project, but need a non-manual way to give us feedback on the new code activity. We have this working for Static analysis since we can look at the dates on the source files. Since Cobertura is analyzing the class files they have new dates and this technique doesn't work.

Any Ideas?

Stack:

Java 1.5 JUnit Cobertura Hudson

like image 203
Andy Avatar asked Sep 03 '10 14:09

Andy


People also ask

How do I find code coverage for new code?

Code coverage option is available under the Test menu when you run test methods using Test Explorer. The results table shows the percentage of the code executed in each assembly, class, and procedure. The source editor highlights the tested code.

How is code coverage measured?

What is Code Coverage? This measures the number of lines of source code executed during a given test suite for a program. Tools that measure code coverage normally express this metric as a percentage. Many use the terms “code coverage” and “test coverage” interchangeably.

What does coverage on new code mean?

What Does Code Coverage Mean? Code coverage is a term used in software testing to describe how much program source code is covered by a testing plan. Developers look at the number of program subroutines and lines of code that are covered by a set of testing resources and techniques.

How do you check new code coverage in SonarQube?

SonarQube and JaCoCo are two tools that we can use together to make it easy to measure code coverage. They also provide an overview of the overall health of the source code by finding code duplications, bugs and other issues in the code. This helps us to know whether our code is production-ready or not.


3 Answers

We had a similar situation.. wanted new code tested but could not test all old code at once. What we did is not exactly what you asked, but may give you an idea.

We have a file called linecoverage.standard, and a file called branchcoverage.standard that live on the build server (and local copies). They have a number inside with the current line and branch coverage limits. If the checked in code is below the standard, it fails the build. If it is at the standard it passes the build. If it is ABOVE the standard, a new standard is written equal to the current coverage.

This means our code coverage will never get worse, and should slowly go up. If new code is 90%, the coverage will keep creeping up. You could also set a goal like raise the standard by 1 each week until it gets to your final goal (90%). Having to add a few tests a week to old code is not a bad idea, if it is spread out over enough time.

Our current coverage is up to 75%ish... pretty good coming from a 0% rate under a year ago.

like image 179
bwawok Avatar answered Oct 24 '22 09:10

bwawok


I did this for a large C++ project by using svn blame combined with the output of gcov. If you zip those two results together you have revision information and coverage information for each line. I actually loaded this all into a database to do queries (e.g. show me all the uncovered lines written by joe since r1234). If you only want an aggregate number you can just avoid counting 'old' uncovered lines in your total.

like image 37
Ben Jackson Avatar answered Oct 24 '22 09:10

Ben Jackson


Have a look on emma.sourceforge and associated Eclipse plugin here (if you are using Eclipse)

I think this tool can answer to your need by selecting exactly what to test for coverage.

like image 40
Manuel Selva Avatar answered Oct 24 '22 10:10

Manuel Selva