how to configure Jacoco for integration tests that runs using maven jetty/tomcat plugin?

858 views
Skip to first unread message

Gaurav Singh

unread,
Nov 9, 2015, 1:58:44 AM11/9/15
to JaCoCo and EclEmma Users

Hi,

We have a REST web application that contains units tests and integration tests,
Integration tests are used to run using maven jetty plugin, our application is exposing REST web services,
we have written integration test using Spring RestTemplate to verify the functionality of api. 

We wanted to generate coverage report after running unit tests and integration tests,
But Jacoco is not including the code coverage report that are being executed by Integration tests however it generates the report for unit tests
When I run command "$ mvn clean verify -P integration-test ", its running all integration tests but at the end report are also getting generated but it shows zero percentage line and branch coverage , 

I followed many post for this, unfortunately none of the post worked for me to achieve this.
could you please help me,


Attached screenshot of report


Project pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Joyious Server</name>

<properties>
<org.springframework.version>4.0.0.RELEASE</org.springframework.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<servlet.version>3.0.1</servlet.version>
<javax.inject.version>1</javax.inject.version>
<hibernate.validator.version>5.1.0.Final</hibernate.validator.version>
<lib.directory>${project.basedir}/src/main/webapp/WEB-INF/lib</lib.directory>
<spring-data-jpa.version>1.4.1.RELEASE</spring-data-jpa.version>
<querydsl.version>3.5.0</querydsl.version>
<!-- Used to locate the profile specific configuration file. -->
<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
<jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
<!-- Only unit tests are run by default. -->
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>

<profiles>
<profile>
<id>all-tests</id>
<properties>
<!-- All tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
<profile>
<id>dev</id>
</profile>
<profile>
<id>integration-test</id>
<properties>
<!-- Used to locate the profile specific configuration file. -->
<build.profile.id>integration-test</build.profile.id>
<!-- Only integration tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>
</profiles>

<dependencies>
.....dependecies...
</dependencies>

<build>
<finalName>joyious</finalName>

<plugins>



<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>localhost</server>
<path>/joyious</path>
<port>9080</port>
</configuration>
<executions>
<execution>
<id>tomcat7-run</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat7-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>



<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Duser.language=en -Duser.country=US -Xms128m -Xmx750m
-XX:PermSize=128m -XX:MaxPermSize=256m</argLine>
</configuration>
<version>2.16</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>


<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<!-- Prepares the property pointing to the JaCoCo runtime agent which 
is passed as VM argument when Maven the Surefire plugin is executed. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo 
runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for unit tests is created 
after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.ut.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent which 
is passed as VM argument when Maven the Failsafe plugin is executed. -->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.it.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo 
runtime agent. -->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests after 
integration tests have been run. -->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- Used for unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/IT.java</exclude>
</excludes>
</configuration>
</plugin>
<!-- Used for integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<!-- Ensures that both integration-test and verify goals of the Failsafe 
Maven plugin are executed. -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>${failsafeArgLine}</argLine>

<!-- Skips integration tests if the value of skip.integration.tests 
property is true -->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>

Best Regards
Gaurav

step...@getkahoot.com

unread,
Dec 18, 2015, 4:26:00 AM12/18/15
to JaCoCo and EclEmma Users
I'm facing the exact same issue.

You had any progress ?

shrey...@gmail.com

unread,
Mar 10, 2016, 6:23:30 AM3/10/16
to JaCoCo and EclEmma Users
> ...

Me too facing the same issue? Any solution for this?
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages