Reputation: 730
I am trying to configure Jacoco agent for code coverage but it's not generating any coverage. This is my current configuration:
I have 2 projects lets call them project A & project B. Project A is where I want to generate coverage report for. Its running on wildfly and I configured Jacoco Agent as vm argument like this:
-javaagent:/jacocoagent.jar=port=36320,destfile=jacoco-it.exec,output=tcpserver
Project B is a maven project from where I am executing the test cases.I configured the jacoco maven plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>generate-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<skip>${skip.int.tests.report}</skip>
<target>
<!-- Execute an ant task within maven -->
<echo message="Generating JaCoCo Reports"/>
<taskdef name="report" classname="org.jacoco.ant.ReportTask">
<classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar"/>
</taskdef>
<mkdir dir="${basedir}/target/coverage-report"/>
<report>
<executiondata>
<fileset dir="${basedir}">
<include name="target/jacoco-it*.exec"/>
</fileset>
</executiondata>
<structure name="jacoco-multi Coverage Project">
<group name="jacoco-multi">
<classfiles>
<fileset dir="target/classes"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="src"/>
</sourcefiles>
</group>
</structure>
<html destdir="${basedir}/target/coverage-report/html"/>
<xml destfile="${basedir}/target/coverage-report/coverage-report.xml"/>
<csv destfile="${basedir}/target/coverage-report/coverage-report.csv"/>
</report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.8.4</version>
</dependency>
</dependencies>
</plugin>
I configured the maven surefire plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<environmentVariables>
<BLUEOPTIMA_HOME>${project.basedir}/</BLUEOPTIMA_HOME>
</environmentVariables>
<systemPropertyVariables>
<BLUEOPTIMA_HOME>${project.basedir}</BLUEOPTIMA_HOME>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>${project.basedir}/testng.xml</suiteXmlFile>
<!--<suiteXmlFile>suites-test-testng.xml</suiteXmlFile> -->
</suiteXmlFiles>
</configuration>
</plugin>
When I execute the mvn test command its not generating any code coverage reports. Any idea what I am doing wrong here?
Upvotes: 0
Views: 648
Reputation: 10564
When I execute the mvn test command
In your configuration goal run
of maven-antrun-plugin
is bound to post-integration-test
phase, which is after test
phase and hence not executed by command mvn test
- see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Upvotes: 0