Need to ignore all log statement in jacoco coverage.

37 views
Skip to first unread message

shruti...@gmail.com

unread,
Jun 29, 2020, 7:25:59 AM6/29/20
to JaCoCo and EclEmma Users
Hi team,

Jacoco is working fine without log statement.But it is giving me error with logs statement as below -

14:05:38     [junit] 
14:05:38     [junit] Testcase: testValidateQwestCktIdVCID took 0.171 sec
14:05:38     [junit] 	Caused an ERROR
14:05:38     [junit] org/apache/log4j/Category
14:05:38     [junit] java.lang.NoClassDefFoundError: org/apache/log4j/Category
14:05:38     [junit] 	at com.qwest.eflow.eman.common.nwf.FOAValidationHandler.<clinit>(FOAValidationHandler.java:44)
14:05:38     [junit] 	at com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverageTest.testValidateQwestCktIdVCID(JacacoCoverageTest.java:31)
14:05:38     [junit] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category
14:05:38     [junit] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
14:05:38     [junit] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
14:05:38     [junit] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
14:05:38     [junit] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
14:05:38     [junit] 
14:05:38     [junit] Testcase: testUncoveredMethod took 0.001 sec
14:05:38     [junit] 	Caused an ERROR
14:05:38     [junit] org/apache/log4j/Category
14:05:38     [junit] java.lang.NoClassDefFoundError: org/apache/log4j/Category
14:05:38     [junit] 	at com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverage.<clinit>(JacacoCoverage.java:6)


I am using apache log4j in my code.

Could you please help me how can I ignore all the log statements in a java class during jacoco coverage.

below is ant configuration for jacoco -

<target name="test" depends="compile">
<jacoco:coverage destfile="${result.exec.file}" excludes="org.apache.log4j.*">
<junit showoutput="true" printsummary="on" enabletestlistenerevents="true" fork="true" haltonfailure="no" forkmode="once">
<classpath path="${result.classes.dir}"/>
<classpath path="${junit.jar.path}"/>
<classpath path="${hamcrest.jar.path}"/>
<classpath location="../../ant-junit-1.9.5.jar"/>
<formatter type="plain" usefile="false"/>
<test name="com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverageTest"/>
</junit>
</jacoco:coverage>
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!--
 This task needs the collected execution data and ...
-->

<executiondata>
<file file="${result.exec.file}"/>
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}"/>
<csv destfile="${result.report.dir}/report.csv"/>
<xml destfile="${result.report.dir}/report.xml"/>
</jacoco:report>
</target>

Please let me know if anything needed from my end.

Marc Hoffmann

unread,
Jun 30, 2020, 5:53:20 AM6/30/20
to JaCoCo and EclEmma Users
If you use log4j it needs to be on the classpath, otherwise you will get a NoClassDefFOundError.

This is not related to JaCoCo. Please make your build work without JaCoCo. JaCoCo cannot fix your classpath.

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/24b019eb-422e-4553-936d-ed1502f14baeo%40googlegroups.com.

shruti...@gmail.com

unread,
Jul 1, 2020, 2:05:23 AM7/1/20
to JaCoCo and EclEmma Users
Hi Mark,

It is not related to build. Build is still working fine. I am getting error for jacoco coverage.
In my classpath, I already have the log4j related jar.

I tried adding jvm-arg for log4j properties in debug configuration. After that I was able to see the coverage in eclipse also for eclemma plugin in my local eclipse workspace, but it is not working for jacoco coverage.
To unsubscribe from this group and stop receiving emails from it, send an email to jac...@googlegroups.com.

Evgeny Mandrikov

unread,
Jul 1, 2020, 4:57:15 AM7/1/20
to JaCoCo and EclEmma Users
Let me rephrase what Marc said:

As highlighted below there is no log4j jar in classpath of "junit" task in your ant script.

Screenshot_2020-07-01_at_09_42_18.png

And so you will be receiving the same ClassNotFoundException even without wrapping "junit" by "jacoco:coverage"

Screenshot_2020-07-01_at_09_42_59.png

If you disagree with the above observations, then please provide complete example, because partial snippets are not debuggable.

shruti...@gmail.com

unread,
Jul 10, 2020, 3:23:40 AM7/10/20
to JaCoCo and EclEmma Users
Thank you Evgeny and Marc,

Now I got the issue. I have added log4j jar in junit classpath and it is working this time :)
Once again thank you so much for helping me with this issue.



On Wednesday, July 1, 2020 at 2:27:15 PM UTC+5:30, Evgeny Mandrikov wrote:
Let me rephrase what Marc said:

As highlighted below there is no log4j jar in classpath of "junit" task in your ant script.

Screenshot_2020-07-01_at_09_42_18.png

And so you will be receiving the same ClassNotFoundException even without wrapping "junit" by "jacoco:coverage"

Screenshot_2020-07-01_at_09_42_59.png

If you disagree with the above observations, then please provide complete example, because partial snippets are not debuggable.


Reply all
Reply to author
Forward
0 new messages