Jacoco not showing coverage from powermock unit test cases.

6,153 views
Skip to first unread message

leela kumili

unread,
May 6, 2015, 1:05:35 PM5/6/15
to jac...@googlegroups.com
Have a multi-module maven project.

Each module has couple of testng and powermock unit test cases. We are using jacoco for code coverage report. But, jacoco is analyzing unit test coverage based on testng unit test cases and ignoring powermock unit test case. So, total code coverage is coming low.

Here is how I have configured the jacoco-maven-plugin and unit-test cases:

Jacoco-Maven-Plugin configuration:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<propertyName>coverageAgent</propertyName>
<append>true</append>
</configuration>
<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>${sonar.jacoco.reportPath}</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>${sonar.jacoco.reportPath}</dataFile>
<excludes>
<exclude>com.walmart.services.*</exclude>
</excludes>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${jacoco.reports.unit.dir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>


Unit-test case profile:

<!-- For mapping unit tests and covered code -->
<profile>
<id>jacoco-ut</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration combine.self="override">
<testFailureIgnore>true</testFailureIgnore>
<threadCount>25</threadCount>
<argLine>${surefireArgLine}</argLine>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.10</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco-maven-plugin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>

Mirko Friedenhagen

unread,
May 6, 2015, 2:00:38 PM5/6/15
to jac...@googlegroups.com

Hello Leela,

please just google for jacoco and powermock, both modify the loaded classes, so depending on your scenario different approaches are valid.

Regards
Mirko
--
Sent from my mobile

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/ebeba784-9a19-4c8a-954f-791176f5cc0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

leela kumili

unread,
May 6, 2015, 2:28:07 PM5/6/15
to jac...@googlegroups.com
Hi Mirko,

Thanks for you response. I have googled but could not find the solution which works for testng+powermock unit test cases together .

Please share if you have found one.

umesh

unread,
Jun 17, 2015, 11:38:36 AM6/17/15
to jac...@googlegroups.com
PowerMock and Jacoco has a work around for maven build projects where you preinstrument the classes but I have tried the same approach in ant build project but this does not seems to work for ant build projects. Evengy Gudkov has provided an example on maven based project to make jacoco and powermock work together in offline mode...It would be really great if you someone could post similar example for ant build projects

Evgeny Mandrikov

unread,
Jun 17, 2015, 3:36:17 PM6/17/15
to jac...@googlegroups.com, umesh.p...@pearson.com
Hi,

Please don't post same questions in multiple threads.

Thanks for your understanding.

praum...@gmail.com

unread,
Jun 17, 2015, 3:40:35 PM6/17/15
to jac...@googlegroups.com


Sure Sorry about that

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages