Code coverage for Maven projects (code coverage)
The structure of Java projects using Maven involves a number of Unit tests.
But tests alone are not enough, I want to have more complete information as far as our tests cover the code.
For these purposes, there are a number of libraries from which I use Emma ( off site ).
First, add Emma instrumentation to our classes after the compile phase (process-classes phase)
As you can see from the example, emma-maven-plugin supports filtering. More about plugin parameters
By default, instrumented classes are created in the $ {project.build.directory} / generated-classes / emma / classes directory.
This directory should be noted as classesDirectory for maven-surefire-plugin:
And last, let's add a report creation in the test phase
As a result, we get the target / site / emma directory with HTML, TXT and XML reports.
Install the Emma plugin (http://wiki.hudson-ci.org//display/HUDSON/Emma+Plugin) and in the project configuration check Record Emma coverage report checkbox.
This plugin uses coverage.xml created by the emma4it plugin.
As a result, we have graphs, tables of percent coverage, etc.
Schedule example (bad):
But tests alone are not enough, I want to have more complete information as far as our tests cover the code.
For these purposes, there are a number of libraries from which I use Emma ( off site ).
Pom.xml configuration
First, add Emma instrumentation to our classes after the compile phase (process-classes phase)
org.sonatype.maven.plugin emma-maven-plugin 1.2 + org. * -org.some.package. * process-classes instrument
As you can see from the example, emma-maven-plugin supports filtering. More about plugin parameters
By default, instrumented classes are created in the $ {project.build.directory} / generated-classes / emma / classes directory.
This directory should be noted as classesDirectory for maven-surefire-plugin:
org.apache.maven.plugins maven-surefire-plugin $ {project.build.directory} / generated-classes / emma / classes
And last, let's add a report creation in the test phase
org.sonatype.maven.plugin emma4it-maven-plugin 1.3 report test report $ {project.build.sourceDirectory}
As a result, we get the target / site / emma directory with HTML, TXT and XML reports.
Hudson
Install the Emma plugin (http://wiki.hudson-ci.org//display/HUDSON/Emma+Plugin) and in the project configuration check Record Emma coverage report checkbox.
This plugin uses coverage.xml created by the emma4it plugin.
As a result, we have graphs, tables of percent coverage, etc.
Schedule example (bad):