-1

Anybody using Jacoco code coverage with Arquillian? My project is a multi module maven project and currently its not showing code coverage of Arquillian tests. Is there any additional changes in Arquillian.xml other than below pom changes?

Build and plugin part in my pom xml is below

  <build>
    <plugins>

      <!-- start Jacoco -->

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.4.201502262128</version>
    <configuration>
        <propertyName>coverageAgent</propertyName>
        <append>true</append>
    </configuration>
    <executions>
        <execution>
            <id>pre-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                <propertyName>surefireArgLine</propertyName>
                <append>true</append>
            </configuration>
        </execution>
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                <outputDirectory>${project.basedir}/../target/coverageReport</outputDirectory>
                <append>true</append>
            </configuration>
        </execution>
        <execution>
            <id>pre-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
                <propertyName>failsafeArgLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>post-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <append>true</append>
                <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
                <outputDirectory>${project.basedir}/../target/coverageReport</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven.surefire.version}</version>
    <configuration>
        <argLine>${surefireArgLine}</argLine>
        <includes>
            <include>**/*TestNG*</include>
        </includes>
        <excludes>
            <exclude>**/Test/**</exclude>
            <exclude>**/*IT*</exclude>
        </excludes>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.7.1</version>
    <configuration>
        <argLine>${failsafeArgLine}</argLine>
        <includes>
            <include>**/*Test*</include>
        </includes>
    </configuration>
</plugin>


     </plugins> 
   </build>  


 <profiles>
    <profile>
        <id>jacoco-integ-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.7.1</version>
                    <configuration>
                        <argLine>${failsafeArgLine}</argLine>
                        <includes>
                            <include>**/*Test*</include>
                        </includes>
                        <properties>
                            <property>
                                <name>listener</name>
                                <value>org.sonar.java.jacoco.JUnitListener</value>
                            </property>
                        </properties>
                    </configuration>
                    <executions>
                            <execution>
                                <id>integration-tests</id>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <argLine>${failsafeArgLine}</argLine>
                                    <properties>
                                <property>
                                    <name>listener</name>
                                    <value>org.sonar.java.jacoco.JUnitListener</value>
                                </property>
                            </properties>
                                    <skipTests>false</skipTests>
                                </configuration>
                            </execution>
                        </executions>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.sonar-plugins.java</groupId>
                <artifactId>sonar-jacoco-listeners</artifactId>
                <version>2.6</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                 <groupId>org.jacoco</groupId>
                 <artifactId>org.jacoco.core</artifactId>
                 <version>${version.jacoco}</version>
                 <scope>test</scope>
              </dependency>
              <dependency>
                 <groupId>org.jboss.arquillian.extension</groupId>
                 <artifactId>arquillian-jacoco</artifactId>
                 <version>1.0.0.Alpha9</version>
                 <scope>test</scope>
              </dependency>

        </dependencies>
    </profile>

    <profile>
        <id>jacoco-unit-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.13</version>
                    <configuration>
                        <argLine>${surefireArgLine}</argLine>
                        <properties>
                            <property>
                                <name>listener</name>
                                <value>org.sonar.java.jacoco.TestNGListener</value>
                            </property>
                        </properties>
                        <includes>
                            <include>**/*TestNG*</include>
                        </includes>
                        <excludes>
                            <exclude>**/FT/**</exclude>
                            <exclude>**/*IT*</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.sonar-plugins.java</groupId>
                <artifactId>sonar-jacoco-listeners</artifactId>
                <version>2.6</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
</profiles>
Raj
  • 115
  • 8
  • Possible duplicate of [Jacoco and Arquillian in a multi module Maven project](http://stackoverflow.com/questions/12354669/jacoco-and-arquillian-in-a-multi-module-maven-project) – Godin Jan 23 '17 at 07:50
  • I have referred this post before posting this question. Still its not working. – Raj Jan 23 '17 at 18:17
  • Truncated snippet of `pom.xml` alone is clearly not enough to reproduce your problem. Please provide complete runnable example ( http://stackoverflow.com/help/mcve ) - this will greatly increase chances and speed in receiving help here. – Godin Jan 23 '17 at 18:37
  • Hi @Godin, My source code is in Module A and I am running integration tests in Module B. There are no source files present in the module where I am running the test. Will jacoco support the multi module coeverage? I am using jacoco version "0.7.4.201502262128" . I am not able to provide my entire pom file or source code as its a violation of the company policy. – Raj Feb 08 '17 at 00:50
  • Yes it is possible to get coverage when tests are located in a separate module. But probably not in the way you're currently doing this. Precise instructions vary from case to case, so can't give them for your your case in absence of precise example of your case. But there are plenty of examples in internet, e.g. have a look on existing questions http://stackoverflow.com/questions/41885772/jacoco-simple-integration-test-solution , http://stackoverflow.com/questions/42088458/find-code-coverage-for-multi-module-maven-project etc – Godin Feb 08 '17 at 10:42

1 Answers1

0

Thanks @Godin for pointing me to the correct solution. I have resolved it by adding below two steps.

1) Parent pom

<plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.8</version>
         <configuration>
            <destFile>${sonar.jacoco.itReportPath}</destFile>
            <append>true</append>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>prepare-agent</goal>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

2) In the child pom where integration Tests run

<plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.8</version>
        <executions>
          <execution>
            <configuration>
              <destFile>${project.build.directory}/jacoco.exec</destFile>
            </configuration>
          </execution>
          <execution>
            <id>it-report</id>
            <phase>verify</phase>
            <goals>           
              <goal>report-aggregate</goal>
            </goals>
            <configuration>
            <!--   <dataFileIncludes>**/jacoco.exec</dataFileIncludes> -->
              <outputDirectory>${project.build.directory}/coverage-reports/jacoco</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

Key is we need to use "report-aggregate" goal instead of "report". "report-aggregate" goal can do multi module code coverage.

Raj
  • 115
  • 8