Search code examples
javamavenunit-testingjacocojacoco-maven-plugin

Jacoco plugin for component tests


I have project structure goes like this

myProject
    app
        module1
            submodule
            pom.xml
        pom.xml
    automation
        component-tests
        pom.xml
    pom.xml
pom.xml

Using Jacoco maven plugin to score the coverage.

component-tests module includes only test folder without any sources. Test is simple unit test that runs application and runs under the hood karate framework which runs full component test of the micro service.

Now after running tests - I see that each module includes jacoco.exec file, regular modules has coverage, however component-tests has jacoco.exec but no data about coverage, somehow it does not perform instrumentation of the all modules code.

I suspect that it is because this module has no sources. I tried to use includes - didn't really helped, since I think it is working in scope of the module.

Below is maven surefire argument
javaagent:/Users/me/.m2/repo/org/jacoco/org.jacoco.agent/0.8.10/org.jacoco.agent-0.8.10-runtime

Any option to turn calculation of coverage of whole project when I run component test module?

<profiles>
<profile>
  <id>coverage</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.11</version>
        <executions>
          <execution>
            <id>generate-jacoco-coverage</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <propertyName>surefireArgLine</propertyName>
            </configuration>
          </execution>
          <execution>
            <id>jacoco-report</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>
<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <argLine>
          ${surefireArgLine}
        </argLine>
      </configuration>
    </plugin>

Solution

  • Here all the answers that I needed

    https://medium.com/javarevisited/merging-integration-unit-and-functional-test-reports-with-jacoco-de5cde9b56e1