How to make Maven unit test code coverage work
<p>In Eclipse, I have used EcLEmma to see the unit test code coverage. Which worked fine.
Therefore I have tried to use the JaCoCo plugin for Maven to see the same report with Surefire from Maven build, or even better, with a certain profile, or in the site cycle. Without success. All suggested solutions here didn't work for me.</p>

<p>What is the best way to get a unit test code coverage report (with surefire)?</p>

<p>[Edit]
to be more specific why jacoco failed for me.... as I got always the
Skipping JaCoCo execution due to missing execution data</p>

<p>from the pom
in the properties </p>

<pre><code>    &lt;jacoco.it.execution.data.file&gt;${project.build.directory}/coverage-reports/jacoco-it.exec&lt;/jacoco.it.execution.data.file&gt;
    &lt;jacoco.ut.execution.data.file&gt;${project.build.directory}/coverage-reports/jacoco-ut.exec&lt;/jacoco.ut.execution.data.file&gt;
</code></pre>

<p>in the Build section</p>

<pre><code>        &lt;pluginManagement&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
                &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
                &lt;version&gt;1.0.0&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;lifecycleMappingMetadata&gt;
                        &lt;pluginExecutions&gt;
                            &lt;pluginExecution&gt;
                                &lt;pluginExecutionFilter&gt;
                                    &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                                    &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                                    &lt;versionRange&gt;${jacoco.version}&lt;/versionRange&gt;
                                    &lt;executions&gt;
                                        &lt;!-- Prepares the property pointing to the JaCoCo runtime agent 
                                            which is passed as VM argument when Maven the Surefire plugin is executed. --&gt;
                                        &lt;execution&gt;
                                            &lt;id&gt;pre-unit-test&lt;/id&gt;
                                            &lt;goals&gt;
                                                &lt;goal&gt;prepare-agent&lt;/goal&gt;
                                            &lt;/goals&gt;
                                            &lt;configuration&gt;
                                                &lt;!-- Sets the path to the file which contains the execution 
                                                    data. --&gt;
                                                &lt;destFile&gt;${jacoco.ut.execution.data.file}&lt;/destFile&gt;
                                                &lt;!-- Sets the name of the property containing the settings for 
                                                    JaCoCo runtime agent. --&gt;
                                                &lt;propertyName&gt;surefireArgLine&lt;/propertyName&gt;
                                            &lt;/configuration&gt;
                                        &lt;/execution&gt;
                                        &lt;!-- Ensures that the code coverage report for unit tests is created 
                                            after unit tests have been run. --&gt;
                                        &lt;execution&gt;
                                            &lt;id&gt;post-unit-test&lt;/id&gt;
                                            &lt;phase&gt;test&lt;/phase&gt;
                                            &lt;goals&gt;
                                                &lt;goal&gt;report&lt;/goal&gt;
                                            &lt;/goals&gt;
                                            &lt;configuration&gt;
                                                &lt;!-- Sets the path to the file which contains the execution 
                                                    data. --&gt;
                                                &lt;dataFile&gt;${jacoco.ut.execution.data.file}&lt;/dataFile&gt;
                                                &lt;!-- Sets the output directory for the code coverage report. --&gt;
                                                &lt;outputDirectory&gt;${project.reporting.outputDirectory}/jacoco-ut&lt;/outputDirectory&gt;
                                            &lt;/configuration&gt;
                                        &lt;/execution&gt;
                                        &lt;!-- Prepares the property pointing to the JaCoCo runtime agent 
                                            which is passed as VM argument when Maven the Failsafe plugin is executed. --&gt;
                                        &lt;execution&gt;
                                            &lt;id&gt;pre-integration-test&lt;/id&gt;
                                            &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                                            &lt;goals&gt;
                                                &lt;goal&gt;prepare-agent&lt;/goal&gt;
                                            &lt;/goals&gt;
                                            &lt;configuration&gt;
                                                &lt;!-- Sets the path to the file which contains the execution 
                                                    data. --&gt;
                                                &lt;destFile&gt;${jacoco.it.execution.data.file}&lt;/destFile&gt;
                                                &lt;!-- Sets the name of the property containing the settings for 
                                                    JaCoCo runtime agent. --&gt;
                                                &lt;propertyName&gt;failsafeArgLine&lt;/propertyName&gt;
                                            &lt;/configuration&gt;
                                        &lt;/execution&gt;
                                        &lt;!-- Ensures that the code coverage report for integration tests 
                                            after integration tests have been run. --&gt;
                                        &lt;execution&gt;
                                            &lt;id&gt;post-integration-test&lt;/id&gt;
                                            &lt;phase&gt;post-integration-test&lt;/phase&gt;
                                            &lt;goals&gt;
                                                &lt;goal&gt;report&lt;/goal&gt;
                                            &lt;/goals&gt;
                                            &lt;configuration&gt;
                                                &lt;!-- Sets the path to the file which contains the execution 
                                                    data. --&gt;
                                                &lt;dataFile&gt;${jacoco.it.execution.data.file}&lt;/dataFile&gt;
                                                &lt;!-- Sets the output directory for the code coverage report. --&gt;
                                                &lt;outputDirectory&gt;${project.reporting.outputDirectory}/jacoco-it&lt;/outputDirectory&gt;
                                            &lt;/configuration&gt;
                                        &lt;/execution&gt;
                                    &lt;/executions&gt;
                                &lt;/pluginExecutionFilter&gt;
                            &lt;/pluginExecution&gt;
                        &lt;/pluginExecutions&gt;
                    &lt;/lifecycleMappingMetadata&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/pluginManagement&gt;
</code></pre>

<p>was my last try but the pom becomes bigger and bigger without any result</p>

<p>which failes with</p>

<p>configuring report plugin org.apache.maven.plugins:maven-jxr-plugin:2.3</p>

<p>configuring report plugin org.jacoco:jacoco-maven-plugin:0.7.5.201505241946</p>

<p>Skipping JaCoCo execution due to missing execution data file:......\target\jacoco.exec</p>

<p>Skipping JaCoCo execution due to missing execution data file:......\target\jacoco-it.exec</p>

<p>.... => long project path</p>