0

Java 1.8. Maven 3.8. I want to generate coverage report of junit tests. So I use this in my pom.xml

                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.4.201502262128</version>
                        <executions>
                            <execution>
                                <id>prepare-ut-agent</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-ut.exec</destFile>
                                    <propertyName>jacoco.agent.ut.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                            <execution>
                                <id>prepare-it-agent</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                                    <propertyName>jacoco.agent.it.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

Open terminal and run test like this:

mvn test -Dtest=com.my_company.myproject.ComponentServiceTest

Tests success finish. But coverage report to generate. File jacoco-it.exec is not exist in target folder

Alexei
  • 14,350
  • 37
  • 121
  • 240

1 Answers1

1

The pom.xml is missing the report goal as mentioned in the comment by @rajani-b.

Here is the configuration for the report goal.

<execution>
  <id>report</id>
  <goals>
    <!--
      Generate coverage reports in xml,csv,html formats
      in folder ${project.build.directory}/site/jacoco
    -->
    <goal>report</goal>
  </goals>
</execution>

Below is the complete <plugin> section for jacoco-maven-plugin for reference.

<plugin>
   <groupId>org.jacoco</groupId>
   <artifactId>jacoco-maven-plugin</artifactId>
   <version>0.7.4.201502262128</version>
   <executions>
      <execution>
         <id>prepare-ut-agent</id>
         <phase>process-test-classes</phase>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <propertyName>jacoco.agent.ut.arg</propertyName>
            <append>true</append>
         </configuration>
      </execution>
      <execution>
         <id>prepare-it-agent</id>
         <phase>pre-integration-test</phase>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <propertyName>jacoco.agent.it.arg</propertyName>
            <append>true</append>
         </configuration>
      </execution>
      <execution>
         <id>prepare-agent</id>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
      </execution>
      <execution>
         <id>report</id>
         <goals>
            <!--
              Generate coverage reports in xml,csv,html formats
              in folder ${project.build.directory}/site/jacoco
            -->
            <goal>report</goal>
         </goals>
      </execution>
   </executions>
</plugin>
Sampada Dubey
  • 359
  • 2
  • 6
Alexei
  • 14,350
  • 37
  • 121
  • 240