2

I am trying to use jacoco with maven. When I run mvn clean test I expect the coverage output to be written to target/coverage-reports however when I open up index.html after the build it's empty.

I checked the following, - The jacoco.exec file is present and it has a bunch of class names in it - In the coverage html there is a link 'Sessions' when I click on it I see a bunch if my classes that seem to have been executed - I see no errors or warnings when I run the maven command

I'm puzzled as to why the report is empty. From all the examples I have seen it seems like this should work. What am I missing?

I am using the following jacoco configuration for the maven plugin

  <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
      <append>true</append>
      <skip>false</skip>
      <excludes/>
      <outputDirectory>${project.build.directory}/coverage-reports/</outputDirectory>
      <dataFile>${project.build.directory}/jacoco.exec</dataFile>
      <includes>
        <include>mypackage.*</include>
      </includes>
      <check>false</check>
    </configuration>
    <executions>
      <execution>
        <id>pre-test</id>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
      </execution>
      <execution>
        <id>post-test</id>
        <goals>
          <goal>report</goal>
        </goals>
        <phase>test</phase>
      </execution>
    </executions>
  </plugin>

UPDATE

Apparently this has something to do with the includes pattern that I have provided. When I remove the includes it does show me coverage but for more than I need. I'm still trying to figure out the pattern to use to do a proper include.

1 Answer 1

2

You need to hook it to surefire as well, change it to

 <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.6.3.201306030806</version>
            <executions>
              <!-- pre-unit-test execution helps setting up some maven property,
                which will be used later by JaCoCo -->
              <execution>
                <id>pre-unit-test</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
                <configuration>
                  <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                  <!-- passing property which will contains settings for JaCoCo agent.
                    If not specified, then "argLine" would be used for "jar" packaging -->
                  <propertyName>surefireArgLine</propertyName>
                </configuration>
              </execution>
              <!-- report phase setup -->
              <execution>
                <id>post-unit-test</id>
                <phase>test</phase>
                <goals>
                  <goal>report</goal>
                </goals>
                <configuration>
                  <!-- output file with report data. -->
                  <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                  <!-- output directory for the reports. -->
                  <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14</version>
            <executions>
              <execution>
                <id>default-test</id>
                <phase>test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <argLine>${surefireArgLine}</argLine>
                </configuration>
              </execution>
            </executions>
            <configuration>
              <argLine>-XX:MaxPermSize=512m</argLine>
            </configuration>
          </plugin>
        </plugins>
  </build>
Sign up to request clarification or add additional context in comments.

4 Comments

Jigar, I do have surefire setup that way. It still does not work.
try feeding the report to some parser, I am not exactly sure the file you are referring to should have html formated data that you are expecting
This config works well, I've just tried it on my workstation.
Please could you expand this answer? I read this several times and still have absolutely no idea what line is relevant and what it is that I need to do to link unit/integration test mojos with Jacoco.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.