JaCoCo 0.8.5 -> code coverage 0%

104 views
Skip to first unread message

Rémi Ollagnier

unread,
Mar 12, 2020, 12:29:25 PM3/12/20
to JaCoCo and EclEmma Users
Hello,

I have a project that uses Thorntail, and Arquillian for testing.
I have configured JaCoCo 0.8.5 to measure my code coverage but it does not detect the lines on which it has passed. Therefore, it returns a report with 0% coverage while the test function is passed.
The report that is generated is located under target\site\jacoco.
To reproduce the problem, I run the command mvn clean verify.
It may not be a bug but more of a configuration issue.

Can you help me please?

I can send you the code that isolates the problem and allows me to reproduce it systematically.
Below you will find part of the files.


pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
<modelVersion>4.0.0</modelVersion>

<groupId>fr.gfi.ecommerce</groupId>
<artifactId>referentiel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>Gfi - ReferentielAPI</name>

<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.thorntail>2.6.0.Final</version.thorntail>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Specify the JDK builder image used to build your application. -->
<fabric8.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</fabric8.generator.from>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>3.2</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
    
<!-- testing -->
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>arquillian</artifactId>
<scope>test</scope>
</dependency>
<dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>fluent-hc</artifactId>
      <version>4.5.2.redhat-2</version>
      <scope>test</scope>
    </dependency>
</dependencies>

<!-- Specify the repositories containing RHOAR artifacts -->
<repositories>
<repository>
<id>redhat-ga</id>
<name>Red Hat GA Repository</name>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>redhat-ga</id>
<name>Red Hat GA Repository</name>
</pluginRepository>
</pluginRepositories>

<profiles>
<profile>
<id>thorntail-v2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <!--  implementation is needed only for Maven 2  -->
                                <rule implementation="org.jacoco.maven.RuleConfiguration">
                                    <element>BUNDLE</element>
                                    <limits>
                                        <!--  implementation is needed only for Maven 2  -->
                                        <limit implementation="org.jacoco.report.check.Limit">
                                            <counter>COMPLEXITY</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.60</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom-all</artifactId>
<version>${version.thorntail}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>microprofile</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>openshift</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</reporting>
</project>

CivilitesEndpointTest.java
package fr.gfi.ecommerce.referentiel.test.endpoints;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Request;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.swarm.jaxrs.JAXRSArchive;

import fr.gfi.ecommerce.referentiel.endpoints.CivilitesEndpoint;


@RunWith(Arquillian.class)
public class CivilitesEndpointTest  {
private static Logger logger = Logger.getLogger(CivilitesEndpoint.class);
@Deployment
  public static JAXRSArchive myDeployment() {
File[] dependencies = Maven.resolver()
.loadPomFromFile("pom.xml")
.importRuntimeDependencies()
.resolve()
.withTransitivity()
.asFile();
return ShrinkWrap.create(JAXRSArchive.class, "referentiel.war")
.addAsResource("project-defaults.yml")
.addAsResource("META-INF/microprofile-config.properties")
.addAsLibraries(dependencies)
.addPackages(true, "fr.gfi.ecommerce");
  }
@Test
    @RunAsClient
    public void getAllCivilites() throws IOException {

.execute().returnResponse();
int status = response.getStatusLine().getStatusCode();
logger.infov("status = {0}", status);
assertTrue(200 == status);
String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name());
logger.infov("content = {0}", content);
assertTrue("{\"code\":\"M\",\"libelle\":\"Monsieur\"}".equals(content));
    }
}


CivilitesEndpoint.java
package fr.gfi.ecommerce.referentiel.endpoints;

import javax.enterprise.context.RequestScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.eclipse.microprofile.metrics.annotation.Metered;
import org.eclipse.microprofile.metrics.annotation.Timed;
import org.jboss.logging.Logger;

import fr.gfi.ecommerce.referentiel.entities.Civilite;

/**
 * API Civilité
 * @author Rémi Ollagnier
 *
 */
@Path("/civilites")
@RequestScoped
public class CivilitesEndpoint {
private static Logger logger = Logger.getLogger(CivilitesEndpoint.class);
/**
* Récupération des civilité en filtrant par type
* @param societeOnly true|false permet d'enlever ou non les civilités concernant les sociétés
* @param particulierOnly true|false permet d'enlever ou non les civilités concernant les particuliers
* @return Liste des civilités correspondantes
*/
@GET
@Produces("application/json")
@Path("/")
@Timed(description = "Timing de l'appel Civilites", name = "civilites-filtre-time", absolute = true)
@Metered(name = "getCivilites")
public Response doGet(@Context UriInfo uriInfo, @QueryParam("societe_only") boolean societeOnly, @QueryParam("particulier_only") boolean particulierOnly) {
logger.infov("doGet : societeOnly={0}, particulierOnly={1}", societeOnly, particulierOnly);
Civilite civilite = new Civilite();
civilite.setCode("M");
civilite.setLibelle("Monsieur");
return Response.ok().entity(civilite).build();
}
}



Best Regards,
Rémi Ollagnier

Evgeny Mandrikov

unread,
Mar 25, 2020, 7:04:11 AM3/25/20
to JaCoCo and EclEmma Users
Hi,


On Thursday, March 12, 2020 at 5:29:25 PM UTC+1, Rémi Ollagnier wrote:
I can send you the code that isolates the problem and allows me to reproduce it systematically.
Below you will find part of the files.

Partial snippets are not debuggable, so yes - please always send the complete example to increase your chances of receiving help.


Regards,
Evgeny

Rémi Ollagnier

unread,
Apr 14, 2020, 5:04:29 AM4/14/20
to jac...@googlegroups.com
Dear Evgeny,

Thanks for your help and sorry to answer you so late.

I carried out a first test which you will find here : https://drive.google.com/file/d/13PM0KIV35FxEmn9KnccPsT1wTGibvehA/view?usp=sharing
In this one, JaCoCo is configured with the default mode. But, there is no hyperlink in the session page.
So I worked on a second test that you will find here : https://drive.google.com/file/d/1Yi2TsCYF7uA735SXqfbgAqWtR0WDB6yh/view?usp=sharing
In this one, JaCoCo is configured in offline mode. However, I do not have a session in the session page.

Best Regards,
Rémi Ollagnier

--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/dLMsTK-803A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/9854f726-7ac8-4fd3-95dc-c16614e32df8%40googlegroups.com.

Evgeny Mandrikov

unread,
Apr 14, 2020, 6:12:19 AM4/14/20
to JaCoCo and EclEmma Users


On Tuesday, April 14, 2020 at 11:04:29 AM UTC+2, Rémi Ollagnier wrote:
Dear Evgeny,

Thanks for your help and sorry to answer you so late.

I carried out a first test which you will find here : https://drive.google.com/file/d/13PM0KIV35FxEmn9KnccPsT1wTGibvehA/view?usp=sharing
In this one, JaCoCo is configured with the default mode. But, there is no hyperlink in the session page.


Prepares a property pointing to the JaCoCo runtime agent that can be passed as a VM argument to the application under test.

Your tests start Wildfly in a separate JVM, so please make sure that this JVM receives the above argument.
Seems that you use Arquillian to start Wildfly, so please refer to Arquillian documentation about how to pass arguments.

For example after modification in attached javaVmArguments.patch
following report is generated

report.png



 
So I worked on a second test that you will find here : https://drive.google.com/file/d/1Yi2TsCYF7uA735SXqfbgAqWtR0WDB6yh/view?usp=sharing
In this one, JaCoCo is configured in offline mode. However, I do not have a session in the session page.

Best Regards,
Rémi Ollagnier

Le mer. 25 mars 2020 à 12:04, Evgeny Mandrikov <mand...@gmail.com> a écrit :
Hi,

On Thursday, March 12, 2020 at 5:29:25 PM UTC+1, Rémi Ollagnier wrote:
I can send you the code that isolates the problem and allows me to reproduce it systematically.
Below you will find part of the files.

Partial snippets are not debuggable, so yes - please always send the complete example to increase your chances of receiving help.


Regards,
Evgeny

--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/dLMsTK-803A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.
javaVmArguments.patch

Rémi Ollagnier

unread,
Apr 14, 2020, 12:03:54 PM4/14/20
to jac...@googlegroups.com
Dear Evgeny,

Thank you so much, I managed to get the code coverage with your corrections.
But, it's not work on Windows 10. I run the command on my RHEL 7.6 with the same code and always fine.
Is there a specific configuration for Windows?

Best regards,
Rémi Ollagnier

To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/dLMsTK-803A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/27aaf18f-d4f0-4001-978d-0cb94ab4cae0%40googlegroups.com.

Evgeny Mandrikov

unread,
Apr 15, 2020, 7:16:37 AM4/15/20
to JaCoCo and EclEmma Users


On Tuesday, April 14, 2020 at 6:03:54 PM UTC+2, Rémi Ollagnier wrote:
Dear Evgeny,

Thank you so much, I managed to get the code coverage with your corrections.
But, it's not work on Windows 10. I run the command on my RHEL 7.6 with the same code and always fine.
Is there a specific configuration for Windows?

Usage of JaCoCo is the same on Windows as on other platforms:
  • JaCoCo agent should be passed to JVM using "-javaagent" argument
  • JVM should be terminated gracefully so that JVM shutdown hook registered by JaCoCo can write data on disk, note that to avoid JVM bugs such as https://bugs.openjdk.java.net/browse/JDK-8154017 you should use the latest updates of JVM
And as was already said in my previous email:
How to do this properly for JVM with Wildfly started by Arquillian - is the question for Arquillian/Wildfly experts/developers.
As well as the questions of different behavior of Arquillian/Wildfly on different platforms.

 

Best regards,
Rémi Ollagnier

To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/dLMsTK-803A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages