I'm migrating a couple of projects from an ant build to a maven one. The build server is , and will remain, Hudson.
I've been having trouble recording code coverage in hudson with cobertura due to the tests run and recorded twice problem.
The project is multi-module and it would be nice, although not required, to have an aggregated output of the code coverage data.
All in all, the solution I'm looking for must:
The solution can be based on Cobertura, or Emma, or any other java code coverage tool.
Update: Running the tests with Emma still duplicates the results and there's no merge
capability, so it's not really usable with multi-module builds.
To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.
JaCoCo is a free Java code coverage tool distributed under the Eclipse Public License. It is an open source free code coverage tool for Java, which has been made by the EclEmma. Features: JaCoCo offers instructions, line and branch coverage.
Sonar is a very cool tool that is easily integrated with Hudson, I really like its organization with multi-module projects. You should give it a try
alt text http://sonar.codehaus.org/wp-content/uploads/2009/08/dashboard.png
It's a bit hackish, but the approach I'm using is to use a modified version of the Maven cobertura plugin (which is available from their repo). It provides a cobertura:generate-report target, so that you can insert cobertura:instrument and cobertura:generate-report into your lifecycle before and after tests run, respectively. That'll get you the coverage data you want without the duplicate test execution/recording.
The underlying problem is that all the non-clover Maven coverage plugins I've run into are built around the idea of running the tests with coverage separately from the main test execution in the Maven lifecycle. This, obviously, results in two sets of test executions. If you're using a freestyle project, you'll only get one set of tests recorded (since, even with two test executions, there's only one copy of the test output), but the Maven project type actually intercepts the Maven mojo executions and records test output/results at test execution time, rather than all at once at the end of the build as freestyle projects do. This has plenty of advantages, but it also has the rather glaring disadvantage that a single test getting executed twice gets counted as two tests.
That said, while I've seen strong arguments for running tests against both non-instrumented and instrumented code, I prefer to only run the tests once, against instrumented code - not just because of the Maven/Hudson issues, but because when you've got tests that take 45 minutes, it seems quite frankly silly to run them twice to generate the same result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With