Integration tests coverage with RestAssured

560 views
Skip to first unread message

Mickael BOREL

unread,
Feb 1, 2021, 4:37:02 PM2/1/21
to JaCoCo and EclEmma Users
Hello,

I'm using Jboss and Rest Assured to implement integration tests, and I want to measure code coverage. For that, I use jacoco with specific maven plugin. 
But my coverage is still equal to 0%.

From what I understand I have to run the jacocoagent from the Jboss VM, that's what I did. One  jacoco.exec is generated but the coverage is null.

Do I need to configure anything else?

Thanks in advance for your help!

Regards

Marc Hoffmann

unread,
Feb 1, 2021, 5:00:55 PM2/1/21
to jac...@googlegroups.com
Hi Mickael,

do you create an JaCoCo HTML report? In this case the report has an “Sessions” link on the to right corner.

On that page, do you see your classes under test listed?

Regards,
-marc


--
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/9a5d8b86-dfef-414d-99ce-ed8b7d044488n%40googlegroups.com.

Mike BO

unread,
Feb 2, 2021, 8:04:22 AM2/2/21
to JaCoCo and EclEmma Users
Hi Marc, and thank you for your feedback,

Yes I have generated a HTML report, but I don't see my classes :( . Only internal jboss classes).
I must have forgotten something, but I don't know what.

Rgds
Mickael

Evgeny Mandrikov

unread,
Feb 3, 2021, 5:57:35 AM2/3/21
to JaCoCo and EclEmma Users
On Tuesday, February 2, 2021 at 2:04:22 PM UTC+1 Mike BO wrote:
Hi Marc, and thank you for your feedback,

Yes I have generated a HTML report, but I don't see my classes :( . Only internal jboss classes).

Hi,

Absence of classes in Session page of HTML report means that execution of these classes was not observed in JVM with agent that generated exec file.
 
I must have forgotten something, but I don't know what.

One can try to ask questions like - are you sure that agent was used in the right JVM?

But IMO highly unlikely that someone will be able to blindly guess what is wrong in your case, unless you provide complete example that others can try.

I tried to use JaCoCo for simple application in WildFly (formerly known as JBoss) as described below and did not faced problem like yours

downloaded
and unpacked it into
/tmp/example/wildfly-21.0.0.Final

downloaded
and unpacked it into
/tmp/example/jacoco-0.8.6

downloaded
into
/tmp/example/wildfly-21.0.0.Final/standalone/deployments/

it contains servlet
mypackage/Hello.class

then I started server with JaCoCo agent as following
JAVA_OPTS=-javaagent:/tmp/example/jacoco-0.8.6/lib/jacocoagent.jar=destfile=/tmp/example/jacoco.exec /tmp/example/wildfly-21.0.0.Final/bin/standalone.sh

then visited page in browser to execute servlet

after that stopped server, so file
/tmp/example/jacoco.exec
was generated

generation of report from it
java -jar /tmp/example/jacoco-0.8.6/lib/jacococli.jar report /tmp/example/jacoco.exec --classfiles /tmp/example/wildfly-21.0.0.Final/standalone/deployments/sample.war --html /tmp/example/report

produces report where 
mypackage/Hello.class
is present in Sessions page - here is screenshot

sessions.png

and on page with coverage metrics

report.png


Regards,
Evgeny

Mike BO

unread,
Feb 3, 2021, 12:02:43 PM2/3/21
to JaCoCo and EclEmma Users
Hi Evgeny,

Thank you for your help. 

You're right, I need to give you more details.

In fact, I'm launching Integration Tests from a pipeline:
  1. These tests are Implemented with RestAssured
  2. and RestAssured uses a JBoss server (installed in a docker).
My pipeline uses maven and the failsafe plugin to run the IT tests.
- part of my pom file:
        <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>integration-tests</id>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <includes>
                                        <include>**/*IT.java</include>
                                    </includes>
                                    <skipTests>false</skipTests>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>${version.jacoco}</version>
                        <executions>
                            <execution>
                                <id>agent-for-it</id>
                                <goals>
                                    <goal>prepare-agent-integration</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report-it</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>report-integration</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

The Jacoco agent is attached on the Jboss JVM.
see: ps -aef result:

 /opt/java/bin/java -D[Standalone] -XX:+UseCompressedOops -verbose:gc -Xloggc:/home/jboss/log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading 
 -server -Djava.net.preferIPv4Stack=true -XX:MaxRAMFraction=2 -Djava.awt.headless=true  -javaagent:./opt/jboss-eap/jacocoagent.jar=destfile=/home/jacoco.exec 
 -Dorg.jboss.boot.log.file=/home/jboss/log/server.log -Dlogging.configuration=file:/opt/jboss-eap/standalone/configuration/logging.properties -jar /opt/jboss-eap/jboss-modules.jar 
 -mp /opt/jboss-eap/modules -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone 
 -Djboss.home.dir=/opt/jboss-eap -Djboss.server.base.dir=/opt/jboss-eap/standalone -Djboss.server.log.dir=/home/jboss/log/ -Djboss.server.temp.dir=/tmp -b 0.0.0.0 -bmanagement 0.0.0.0 -Ddocker.jboss.log.level=INFO

My application is deployed and all tests are success.
But the coverage remains at 0%, and when I check the session view, I don't see my classes.

session.PNG

coverage.PNG
If, for Marc and you, it's due to the fact the agent is not in the right JVM, to be honest I dont know where to put it :(

I'm sure I'm missing something, because your example is clear and work fine.

Thanks 
Best regards
Mickael

Marc Hoffmann

unread,
Feb 3, 2021, 1:24:12 PM2/3/21
to JaCoCo and EclEmma Users
Is this the only running VM? Some application servers fork VMs.


<session.PNG>
--
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/338b0fe9-6d16-4095-8c0b-4445e67391cdn%40googlegroups.com.
<coverage.PNG><session.PNG>

Evgeny Mandrikov

unread,
Feb 3, 2021, 4:59:59 PM2/3/21
to JaCoCo and EclEmma Users
On Wednesday, February 3, 2021 at 6:02:43 PM UTC+1 Mike BO wrote: 
  1. and RestAssured uses a JBoss server (installed in a docker).

The Jacoco agent is attached on the Jboss JVM.
see: ps -aef result:

 /opt/java/bin/java -D[Standalone] -XX:+UseCompressedOops -verbose:gc -Xloggc:/home/jboss/log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading 
 -server -Djava.net.preferIPv4Stack=true -XX:MaxRAMFraction=2 -Djava.awt.headless=true  -javaagent:./opt/jboss-eap/jacocoagent.jar=destfile=/home/jacoco.exec 
 -Dorg.jboss.boot.log.file=/home/jboss/log/server.log -Dlogging.configuration=file:/opt/jboss-eap/standalone/configuration/logging.properties -jar /opt/jboss-eap/jboss-modules.jar 
 -mp /opt/jboss-eap/modules -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone 
 -Djboss.home.dir=/opt/jboss-eap -Djboss.server.base.dir=/opt/jboss-eap/standalone -Djboss.server.log.dir=/home/jboss/log/ -Djboss.server.temp.dir=/tmp -b 0.0.0.0 -bmanagement 0.0.0.0 -Ddocker.jboss.log.level=INFO


Here is one more attempt to guess:
file
/home/jacoco.exec
is created inside of Docker container.
While seems that report is created outside of container.
So are you sure that creation of report uses correct file??

But in my opinion such attempts to guess are counterproductive waste of time both for you and for others.
So let me highlight the following one more time:
unlikely that someone will be able to blindly guess what is wrong in your case, unless you provide complete example that others can try
Partial snippets are definitely not enough to reproduce your complex setup - they are not a complete example that others can try.

So please try to create simple small example that others can try. And share it completely, for example in repository on GitHub.
And BTW maybe by doing this you will be able to find your problem by yourself.

Mike BO

unread,
Feb 5, 2021, 12:26:54 PM2/5/21
to JaCoCo and EclEmma Users
Hello, 

OK I'm going to create a simple example.
Thank you for your help,  and sorry for taking up your time.

Rgds
M.

Saanvi Mendiratta

unread,
Dec 5, 2021, 11:34:50 AM12/5/21
to JaCoCo and EclEmma Users
Hi Mike,

Whether you are able to create a sample application for getting Integration test coverage with Rest Assured. Please share the link so that i can go through it

Sudip Mitra

unread,
Feb 28, 2023, 12:25:12 PM2/28/23
to JaCoCo and EclEmma Users
Is any able to generate code coverage for RestAssured testcases yet using jacoco ? I am seeing lots of discussion on using same jvm. Can you tell how to ensure that ? In the mean time I will give you a sample project where I am trying this.
Reply all
Reply to author
Forward
0 new messages