OS - Windows7
JDK - 1.6 / (I tried with JDK 1.7 as well)
Jacoco - latest Jars
Below is the task definition
<jacoco:coverage destfile="reports/jacoco.exec" exclclassloader="javassist.Loader">
<junit printsummary="yes" haltonfailure="yes" fork="yes" showoutput="yes">
<formatter type="xml"/>
<classpath>
<pathelement location="${test.classes.dir}"/>
<pathelement location="${target.classes.dir}"/>
<pathelement location="C:\kedar\work\CodeCoverage\DF1073Base\target\classes"/>
<fileset dir="${slib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
<batchtest fork="no" todir="reports">
<fileset dir="test">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<jacoco:report>
<executiondata>
<file file="reports/jacoco.exec"/>
</executiondata>
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${test.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="src"/>
</sourcefiles>
</structure>
<html destdir="reports"/>
<csv destfile="reports/report.csv"/>
<xml destfile="reports/report.xml"/>
</jacoco:report>
</target>
If I keep "batchtest fork="no"" - Jacoco executes the Test cases successfully - But Does not generate jacoco.exec file. Can someone help to identify - Why is not generating the jacoco.exec file?
If I keep "batchtest fork="yes/true"" - Jacoco generates jacoco.exec file, but all the test cases fail saying "Class not found sun/reflect/GeneratorAccessorMethod".
Please let me know if more information is required.
Hi Marc,
Thanks for response, sorry for late reply.
We have
1. Jacoco 0.7.5
2. JDK 1.6.29 (Also Tried with JDK 1.7)
3. Stack Trace when 'fork='yes' in batchtest target
Buildfile: C:\batch\build.xml
test:
[delete] Deleting directory C:\batch\target\classes\test
[mkdir] Created dir: C:\batch\target\classes\test
[javac] Compiling 2 source files to C:\batch\target\classes\test
[javac] WARNING
[javac] The -source switch defaults to 1.7 in JDK 1.7.
[javac] If you specify -target 1.6 you now must also specify -source 1.6.
[javac] Ant will implicitly add -source 1.6 for you. Please change your build file.
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 warning
[delete] Deleting directory C:\batch\reports
[mkdir] Created dir: C:\batch\reports
[jacoco:coverage] Enhancing junit with coverage
[junit] Running com.citi.doddfrank.batch.DFBICSortMapDataUploadTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.847 sec
[junit] log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
[junit] log4j:WARN Please initialize the log4j system properly.
[junit] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[junit] Running batch.ABCTest
[junit] Exception in thread "main" java.lang.NoClassDefFoundError: sun/reflect/GeneratedMethodAccessor4
[junit] at sun.reflect.GeneratedMethodAccessor4.<init>(Unknown Source)
[junit] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[junit] at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
[junit] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
[junit] at java.lang.reflect.Constructor.newInstance(Unknown Source)
[junit] at java.lang.Class.newInstance(Unknown Source)
[junit] at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source)
[junit] at sun.reflect.MethodAccessorGenerator$1.run(Unknown Source)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at sun.reflect.MethodAccessorGenerator.generate(Unknown Source)
[junit] at sun.reflect.MethodAccessorGenerator.generateMethod(Unknown Source)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[junit] at java.lang.reflect.Method.invoke(Unknown Source)
[junit] at org.apache.commons.logging.LogFactory.getContextClassLoader(LogFactory.java:442)
[junit] at org.apache.commons.logging.LogFactory$1.run(LogFactory.java:222)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:218)
[junit] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
[junit] at org.springframework.test.annotation.ProfileValueUtils.<clinit>(ProfileValueUtils.java:40)
[junit] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.getDescription(SpringJUnit4ClassRunner.java:152)
[junit] at org.junit.runner.Runner.testCount(Runner.java:41)
[junit] at junit.framework.JUnit4TestAdapter.countTestCases(JUnit4TestAdapter.java:34)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:519)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1060)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:911)
[junit] Running batch.ABCTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
BUILD FAILED
C:\work\CodeCoverage\abc\build.xml:274: Test batch.ABCTest failed (crashed)
Total time: 21 seconds
You are spot on Marc. That was exactly the problem. Thanks for your help.
You deserve a Party from my end :)