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

    Pom.xml configuration

    First, add Emma instrumentation to our classes after the compile phase (process-classes phase)
    org.sonatype.maven.pluginemma-maven-plugin1.2+ org. *-org.some.package. *process-classesinstrument

    As you can see from the example, emma-maven-plugin supports filtering. More about plugin parameters

    By default, instrumented classes are created in the $ {} / generated-classes / emma / classes directory.

    This directory should be noted as classesDirectory for maven-surefire-plugin:
    org.apache.maven.pluginsmaven-surefire-plugin$ {} / generated-classes / emma / classes

    And last, let's add a report creation in the test phase
    org.sonatype.maven.pluginemma4it-maven-plugin1.3reporttestreport$ {}

    As a result, we get the target / site / emma directory with HTML, TXT and XML reports.


    Install the 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):

    Also popular now: