0

I got a multi-module maven project on which i want to generate a jacoco report with the unit coverage. Currently i am using arqullian surefire and jacoco maven plugins, which both are defined in only one module. The tests run on a JBoss EAP 7.2

Although the jacoco report is generated, i always get a 0% coverage on all my test classes which are deployed as an archive org.jboss.shrinkwrap.api.spec.WebArchive on my JBoss server even though there are several methods covered by the Unit tests.
Important: Other unit tests performed without a deployment, do show some coverage on the report

enter image description here

Below is my maven configuration

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.2</version>
      <configuration>
         <skip>${skipTests}</skip>
         <argLine>${surefireArgLine}</argLine>
      </configuration>
   </plugin>
   <plugin>
      <artifactId>maven-surefire-report-plugin</artifactId>
      <version>2.22.2</version>
   </plugin>
   <plugin>
      <groupId>org.jacoco</groupId>
      <artifactId>jacoco-maven-plugin</artifactId>
      <version>0.8.5</version>
      <executions>
         <execution>
            <id>pre-unit-test</id>
            <goals>
               <goal>prepare-agent</goal>
            </goals>
            <configuration>
               <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
               <propertyName>surefireArgLine</propertyName>
            </configuration>
         </execution>
         <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
               <goal>report</goal>
            </goals>
            <configuration>
               <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
               <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
            </configuration>
         </execution>
      </executions>
   </plugin>
</plugins>

Below my dependencies used:

<dependency>
    <groupId>org.dbunit</groupId>
    <artifactId>dbunit</artifactId>
    <version>2.7.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-api-maven</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-spi</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-core</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-container</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.protocol</groupId>
    <artifactId>arquillian-protocol-servlet</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jacoco</groupId>
    <artifactId>org.jacoco.core</artifactId>
    <version>0.8.5</version>
    <scope>test</scope>
</dependency>

Arqulian XML

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian         http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
   <!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
   <defaultProtocol type="Servlet 3.0" />
   <!-- Example configuration for a remote JBoss EAP 7 instance -->
   <container qualifier="jboss" default="true">
      <!-- If you want to use the JBOSS_HOME environment variable, just delete the jbossHome property -->
      <configuration>
         <!--   <property name="javaVmArguments">${jacoco.agent}</property>  -->
      </configuration>
   </container>
</arquillian>

On one of my configurations (not the above), i remember seeing a warning that the ${jacoco.agent} was not used. So i did comment it out again.

When running the mvn clean install goal, in my console logs i see following variables set to the surefireArgLine

[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (pre-unit-test) @ alis-ejb ---
[INFO] surefireArgLine set to -javaagent:C:\\Users\\user\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.5\\org.jacoco.agent-0.8.5-runtime.jar=destfile=c:\\Projects\\Projectname\\ejb-module\\target\\coverage-reports\\jacoco-ut.exec

All my tests are executed normaly and i am able to generate a surefire report command with surefire-report that lists all the unit test executions. I am thinking if am missing a mvn goal for jacoco that calculates the coverage, but it looks that i am still missing something

Update 1: I start to believe that the issue is created due to the usage of Arquilian, and i should use the pre-integration-test phases instead. But not sure yet.

Update 2: I just noticed that for one of my Unit tests i see some coverage. The difference between this unit test and the rest is the one Class containing the tests of which a coverage as shown, are simple Unit tests, whereas for the rest of my Test classes on which i do not get a coverage report from Jacoco a org.jboss.shrinkwrap.api.spec.WebArchive deployment is created. Some more details on this. 90% of my tests, are of this structure. A webarchive is created and deployed on JBoss EAP 7.

Stephan
  • 696
  • 15
  • 37
  • 1
    is the jacoco exec file generated? – Robert Kleinschmager Jun 16 '20 at 13:33
  • Yes. Under the path /coverage-reports/jacoco-ut.exec as defined in the pom.xml – Stephan Jun 17 '20 at 05:32
  • 1
    I can't reproduce exactely your issue. What value is the `${surefireArgLine}`argument set to? What would you also like to do? Generate a single report gathering all modules information? – potame Jun 18 '20 at 11:40
  • i have updated my question provided further information concerning dependencies, arqulian and surefireArgLine . Please note mu "Update 2" comment. My issue may be there. – Stephan Jun 19 '20 at 09:12
  • I made some further changes adding arquillian-jacoco-with-asm (to avoid some conflicts with CXF's ASM), arquillian-core-impl-base, arquillian-core-api, arquillian-junit-container, arquillian-junit-core which looks more correct to me, but now im receiving an error from ASM : Caused by: org.jboss.arquillian.extension.jacoco.org.objectweb.asm.MethodTooLargeException: Method too large: org/drools/compiler/lang/DRL5Lexer.mID ()V . Unfortunately this class is provided by the Drools Engine and i cannot modify it. So i guess i am coming to a dead end ? – Stephan Jun 19 '20 at 12:09
  • jacoco results are written on shutdown of the JVM, and JBoss use to interfere with that. Look around, but I think the work around was some sort of shutdown hook that you had to add in so that JBoss played more nicely. – Jeff Bennett Jun 19 '20 at 20:09

0 Answers0