Hi ,
I need to do code coverage for my application.
If I run the test case with 'Run As - Junit' in Eclipse, test case executes
successfully.
But when I am trying to run the test case using test target, it gives me
exception -pasted at end.
OS - Windows7
JDK - 1.6
Ant/Hemcreast - latest jar
Jacoco/agent - latest jar
Test Class
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"/applicationContextTestJunit.xml",
"/common-context.xml",
"/com/batch/jobs/datapreparation/ODPreparationJob.xml"})
public class ODPreparationTest {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
System.out.println("Executing Setup....");
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
System.out.println("Executing Tear down....");
}
@Test
public void testDataPreparation() throws Exception {
System.out.println("Executing Test....1");
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
System.out.println("Executing Test....2");
Assert.assertEquals("COMPLETED", jobExecution.getExitStatus()
.getExitCode());
System.out.println("Executing Test....3");
}
}
Jacoco portion of build.xml
<target name="test" description="Compile test files">
<delete dir="${test.classes.dir}" />
<mkdir dir="${test.classes.dir}" />
<!-- Compile Java source -->
<javac target="1.6" srcdir="${basedir}/test"
destdir="${test.classes.dir}" debug="${debug}" includeAntRuntime="no"
failonerror="false">
<classpath refid="all-test-libs" />
</javac>
<copy todir="${target.classes.dir}" preservelastmodified="true"
filtering="true">
<fileset dir="${resource.dir}">
<include name="**/*.*" />
</fileset>
</copy>
<copy todir="${target.meta-inf.dir}"
preservelastmodified="true" filtering="true">
<fileset dir="${setup.meta-inf.dir}">
<include name="**/*.*" />
</fileset>
</copy>
<delete dir="reports" />
<mkdir dir="reports" />
<jacoco:coverage destfile="reports/jacoco.exec"
exclclassloader="javassist.Loader">
<junit printsummary="yes"
haltonfailure="false" fork="yes"
forkmode="once" showoutput="yes">
<formatter type="xml" />
<classpath refid="all-final-libs" />
<batchtest fork="yes" todir="reports">
<fileset dir="test">
<include name="**/*Test*.java"
/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<jacoco:report>
<!--
This task needs the collected execution data and ...
-->
<executiondata>
<file file="reports/jacoco.exec" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${test.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="src" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="reports" />
<csv destfile="reports/report.csv" />
<xml destfile="reports/report.xml" />
</jacoco:report>
</target>
Exception:
Running com.batch.ODPreparationTest
[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)
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jacoco/7cacc0f3-4183-4b14-9a50-aa06d2f5657d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.