No Line Level Coverage for WebServices project.

56 views
Skip to first unread message

pran...@hotmail.com

unread,
Mar 27, 2018, 12:11:59 PM3/27/18
to JaCoCo and EclEmma Users
Hello,
I have a RESTFul web service project that has a couple of get and put calls. This is a Maven project and from now I will refer to it as 'Dev project' from now on.
I have compiled this project with the debug flag and have deployed the webapp on Glassfish.

I also have an integration test project that is a separate maven project and makes calls to the Dev project. In the POM of this project I am preparing the Java agent and am copying the .class files of the Dev project to a certain location under the target folder of the test project. The tests in this project make web service end points implemented in the Dev project and my goal is to get coverage when I run 'mvn verify'.


The issue here is when a report is generated there is no line level coverage even though the class level coverage seems accurate. Could you please point out what am I missing because of which the report is missing line level coverage.

TEST POM:
<build>
<finalName>JaxRsAppTest</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports-test/jacoco-test-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>
<dataFile>${project.build.directory}/coverage-reports-test/jacoco-test-it.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-test-it</outputDirectory>
</configuration>
</execution>
</executions>

</plugin> <!-- copies the Dev project's class files to the target of the test project>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>S:/JaxRsApp/Test/test-JaxRS/target/classes</outputDirectory>
<resources>
<resource>
<directory>S:/JaxRsApp/Dev/dmahapat_JaxRsApp/target/classes</directory>
<filtering>false</filtering>

</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>${failsafeArgLine}</argLine>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>

</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>

Thanks in advance.


Evgeny Mandrikov

unread,
Mar 27, 2018, 5:23:42 PM3/27/18
to JaCoCo and EclEmma Users
Hi,

"report" goal ( http://www.jacoco.org/jacoco/trunk/doc/report-mojo.html ) generates report containing source files of a current module by design, even if you are trying to trick it by copying class files.

There is "report-aggregate" ( http://www.jacoco.org/jacoco/trunk/doc/report-aggregate-mojo.html ) for generation of report for multiple projects within same reactor.
This includes the case, when tests are in separate modules than the code under test - https://stackoverflow.com/a/41901853/244993

For more complex scenarios, e.g. when projects are not part of same Maven reactor, use other integration, e.g. e.g. JaCoCo Ant Tasks with maven-antrun-plugin or JaCoCo command line interface.

pran...@hotmail.com

unread,
Mar 30, 2018, 1:53:10 PM3/30/18
to JaCoCo and EclEmma Users
Hello Evgeny,
Would it be possible for you to take a look at the POM. I tried using maven-antrun-plugin but am still not seeing line level coverage:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.abc.qe</groupId>
<artifactId>test-JaxRS</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JaxRsAppTest</name>

<build>
<finalName>JaxRsAppTest</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports-test/jacoco-test-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>

</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>default-report</id>
<phase>verify</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef name="report" classname="org.jacoco.ant.ReportTask" classpathref="maven.plugin.classpath" />
<report>
<executiondata>
<file file="${project.build.directory}/coverage-reports-test/jacoco-test-it.exec" />
</executiondata>
<structure name="Coverage">
<classfiles>
<fileset dir="S:/JaxRsApp/Dev/dmahapat_JaxRsApp/target/classes"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="S:/JaxRsApp/Dev/dmahapat_JaxRsApp/src"/>
</sourcefiles>
</structure>
<check failonviolation="false" violationsproperty="violation">
<!--<rule element="BUNDLE">
<limit counter="INSTRUCTION" value="COVEREDRATIO" minimum="0.00" />
</rule>-->
</check>
<html destdir="${project.build.directory}/jacoco-internal"/>
</report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.7.9</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>

<phase>validate</phase>

</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
</dependency>
</dependencies>
<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>
</project>


Many thanks in advance.

Evgeny Mandrikov

unread,
Mar 30, 2018, 2:09:00 PM3/30/18
to JaCoCo and EclEmma Users
Hi,

I'm a bit tired to repeat that POM alone is never enough to reproduce problem and hence almost never enough to understand/guess what's wrong - see here https://groups.google.com/d/msg/jacoco/5-Kwo2s2u9A/QHDqnkTkAwAJ and there https://groups.google.com/d/msg/jacoco/8FWk3_nAlkM/tOsFasR-CwAJ , etc.

But ok, let's try to guess based on http://www.jacoco.org/jacoco/trunk/doc/faq.html :

Why does the coverage report not show line coverage figures?
JaCoCo is based on class files analysis. To calculate line coverage class files must contain line number attributes. For this your code must be compiled with debug information.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages