Code coverage of an EAR running on Jboss using JaCoco

558 views
Skip to first unread message

Abhay Hegde

unread,
Dec 2, 2020, 1:06:04 AM12/2/20
to JaCoCo and EclEmma Users

I have an MyApp.ear containing production code and a test.war containing end-to-end test code deployed in the same JBoss server on the same host machine.

MyApp.ear accepts MQ messages and returns the output.

test.war sends the MQ messages and asserts the output.

Both production and test application is built using maven. I am using jacoco 0.8.5 for code coverage. 

An end-to-end test is invoked as below in the command line: 

$mvn clean verify -DJBOSS_HOME=<path_to_jboss_dir> -f=integration-test/pom.xml jacoco:prepare-agent jacoco:report sonar:sonar -Dsonar.skip=false -Dit.test=com.mypackage.name.EndToEndTest 


Test execution flow is as below:

  1. A test class sends the MQ messages to the MQs that are configured in the host.
  2. Production class (MyApp.ear)   listens to the queue and accepts the MQ messages for processing.
  3. Processed output is asserted by the test class using Junit.

 Questions:

  • Is it possible to obtain the code coverage of my production classes when i run the End to end test ?
  • If yes, would appreciate if you could point out few key things to be done.
Thanks
Abhay


Abhay Hegde

unread,
Dec 4, 2020, 12:50:57 AM12/4/20
to JaCoCo and EclEmma Users
I have tried the following, please correct me if I am wrong:

1. export JAVA_OPTS=-javaagent:<path_to>/jacocoagent.jar=destfile=<path_to>/jacoco-it.exec
2. Start JBoss server.
3. Run the Integration test using maven.
4. Stop the JBoss server.
5. Run the command:
java -jar <path_to>/jacococli.jar report <path_to>/jacoco-it.exec --classfiles=<path_to_production_code_jar_file> --csv=coverage-reports/report_in_csv
Above step will update the jacoco-it.exec with all the instrumented classes.
6. Coverage report will be present in report_in_csv given in Step 5.  

Thanks
Abhay

Marc Hoffmann

unread,
Dec 4, 2020, 2:25:31 AM12/4/20
to JaCoCo and EclEmma Users
Hi Abhay,

this looks like the correct approach. It is always two steps:

1) Collect execution data on the JVM that runs the production code using the JaCoCo agent
2) Create coverage report from the exec file(s) from step 1) and the same class files used in step 1)

Glad to hear that this works for you!

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/a6311112-d720-41c7-b159-f132e3312e5cn%40googlegroups.com.

abhay hegde

unread,
Dec 4, 2020, 12:46:17 PM12/4/20
to jac...@googlegroups.com
Hi Marc,

thank you, for clearing that up! Another question :)

1. As per JaCoco document,the --classfiles=<path_to_production_code_jar_file> supports multiple jar files. Since all my jars are bundled inside the application.ear , how do I provide those as argument?.

Regards
Abhay


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/0QkOV5u1w6Y/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/9B08C031-3069-49A7-96B6-8EBB6F51BFA1%40mountainminds.com.


--
LinkedIN - Abhay Hegde
Contact:- +91 9000011822
Skype - abhayhegde

Marc Hoffmann

unread,
Dec 6, 2020, 6:28:06 AM12/6/20
to JaCoCo and EclEmma Users
Just provide the *.ear file. JaCoCo traverses archive formats recursively and will find all jars and class files in the ear.
 

Abhay Hegde

unread,
Dec 14, 2020, 5:59:53 AM12/14/20
to JaCoCo and EclEmma Users
Thank you Marc. 
When I try that, i am faced with :

Exception in thread "main" java.io.IOException: Error while analyzing ../myApp/target/myApp.ear@shared/log4j-api.jar@META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class
Caused by: java.lang.IllegalStateException: Can't add different class with same name: org/apache/logging/log4j/util/ProcessIdUtil

I went through the FAQ and got to know the reason why it occurs.

Please correct me if I am wrong. I see 2 options:
1. To remove those jars from the .ear.
2. To exclude those from instrumentation and reporting all together.

To exclude from instrumentation, i added below to javaagent 
excludes=<absolute_path>/myApp.ear/shared/log4j-api.jar/META-INF/*

To exclude from report, I appended the excludes to jacococli.jar command line, as below:
java -jar <absolute_path>/jacoco-it.exec --classfiles myApp.ear --html=target/html_report --excludes=<absolute_path>/myApp.ear/shared/log4j-api.jar/META-INF/*

I end up facing the same exception. Is it the correct approach?

Regards
Abhay

Marc Hoffmann

unread,
Dec 14, 2020, 8:06:00 AM12/14/20
to JaCoCo and EclEmma Users
Hi Abhay,

yes, you would need to remove those duplicate from the ear .You can also unzip the ear file, remove the 3rd party JAR from the file system and then run the report generator with this folder.

Note that this is only an issue with reporting. Multiple different classes can be handled at instrumentation and runtime. Excluding such classes from instrumentation does not fix the report.

Regards,
-marc

Reply all
Reply to author
Forward
0 new messages