How to collapse jUnit output to summary, using ANT? - ant

My test target looks as follows:
<target name="test" depends="compileTest">
<junit haltonfailure="yes">
<classpath>
<pathelement location="bin" />
<pathelement location="lib/xstream-1.4.2.jar" />
<pathelement location="lib/jettison-1.2.jar" />
</classpath>
<formatter type="plain" usefile="false" />
<batchtest>
<fileset dir="${test-src}">
<include name="**/*Test*" />
</fileset>
</batchtest>
</junit>
</target>
And output looks as follows:
test:
[junit] Testsuite: app.commons.error.test.ShellErrorMessageTest
[junit] Tests run: 9, Failures: 0, Errors: 0, Time elapsed: 0.006 sec
[junit] Testcase: testCreateNormal took 0.003 sec
[junit] Testcase: testGetSectionSeparatorLine took 0.001 sec
[junit] Testcase: testGetSectionSeparatorLineMultipleSymbols took 0 sec
[junit] Testcase: testGetSectionSeparatorLineEmptySymbol took 0 sec
[junit] Testcase: testGetSectionSeparatorLineEmptySymbolSpace took 0 sec
[junit] Testcase: testGetSectionSeparatorLineNull took 0 sec
How can i collapse this output to a 1 line summary?
Is there a way to receive 1 line output along the line of "Ran 500 tests. 0 Failures. 0 Errors"

You can set an unverbose junit-output by adding
<formatter type="brief" usefile="false"/>
within <junit>.
To further reduce it, the following options come to my mind:
use a standard unix/cygwin tool to filter the output,
add a <junitreport>-task within <junit>, or
check the free exemplary chapter "Testing with JUnit" from "Java Development with Ant, they probably have some advice for you in there.

Related

Jacoco coverage giving ERROR for org/apache/log4j/Category in java class

I am trying to do the code coverage using Jacoco. I have written the Jacoco configuration in ANT script.Jacoco working fine without logs in code.
But it is error out for loggers (apache log4j) added in my code.
I tried to exclude the logs by adding below code in my ant script as <jacoco:coverage destfile="${result.exec.file}" excludes="org.apache.log4j.*">
still it is giving me same error.
I am getting below exception:
15:35:16 [junit] Testcase: testUncoveredMethod took 0.009 sec
15:35:16 [junit] Caused an ERROR
15:35:16 [junit] org/apache/log4j/Category
15:35:16 [junit] java.lang.NoClassDefFoundError: org/apache/log4j/Category
15:35:16 [junit] at com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverage.<clinit>(JacacoCoverage.java:6)
15:35:16 [junit] at com.ant.sonar.jacoco.junit.code.coverage.JacacoCoverageTest.testUncoveredMethod(JacacoCoverageTest.java:23)
15:35:16 [junit] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Category
15:35:16 [junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
15:35:16 [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
15:35:16 [junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
15:35:16 [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
Jacoco configuration
<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>
I got the fix for this issue. Need to add log4j jar in junit classpath

emma - no runtime coverage data found

I can't define why emma isn't generating the runtime coverage data.
What I'm forgetting when running the tests?
based on the this post:
How to change Ant script with EMMA code-coverage so it can find runtime coverage data?
I put the instrumented classes in the top of the classpath
ant-emma.xml:
<!-- ====================================================================-->
<!-- EMMA SETUP -->
<!-- ====================================================================-->
<project name="Emma" basedir="." >
<property file="./emma.properties" />
<property name="emma.lib.dir" location="${emma.home}/lib" />
<property name="emma.build.dir" location="${build.dir}/emma" />
<property name="emma.instr.dir" location="${emma.build.dir}/target" />
<!-- directory which emma instrumentation classes will be written to -->
<property name="emma.instr.src.dir" location="${emma.instr.dir}/src" />
<property name="emma.instr.test.dir" location="${emma.instr.dir}/test" />
<property name="emma.report.dir" location="${emma.build.dir}/report" />
<!-- directory which emma coverage reports will be written to -->
<property name="emma.data.dir" location="${emma.report.dir}/data" />
<property name="emma.runtime.coverage.data.file" location="${emma.data.dir}/coverage.ec" />
<property name="emma.coverage.merged.dir" location="${emma.data.dir}/final" />
<property name="emma.coverage.file" location="${emma.coverage.merged.dir}/coverage-final.emma" />
<property name="emma.filter" value="" />
<path id="emma.lib.path" >
<pathelement location="${emma.lib.dir}/emma.jar" />
<pathelement location="${emma.lib.dir}/emma_ant.jar" />
</path>
<!-- Define which classes will be reported in the coverage reports (by default, we will include all classes and assume -->
<!-- that your project's output folder is target/classes -->
<path id="emma.coverage.classes" >
<pathelement location="${build.src.dir}" />
<pathelement location="${build.test.dir}" />
</path>
<path id="classpath.emma.run" >
<pathelement location="${emma.instr.src.dir}" />
<pathelement location="${emma.instr.test.dir}" />
<pathelement location="${build.test.dir}" />
<pathelement location="${build.src.dir}" />
<path refid="classpath.src.compile" />
<path refid="emma.lib.path" />
</path>
<taskdef resource="emma_ant.properties" classpathref="emma.lib.path" />
<target name="emma-clean" >
<delete includeemptydirs="true" quiet="false" verbose="false" failonerror="true" dir="${emma.report.dir}" />
<delete includeemptydirs="true" quiet="false" verbose="false" failonerror="true" dir="${emma.instr.dir}" />
<delete includeemptydirs="true" quiet="false" verbose="false" failonerror="true" dir="${emma.build.dir}" />
</target>
<target name="emma-init" depends="emma-clean">
<mkdir dir="${emma.build.dir}" />
<mkdir dir="${emma.report.dir}" />
<mkdir dir="${emma.instr.dir}" />
<mkdir dir="${emma.report.dir}" />
<mkdir dir="${emma.data.dir}" />
<mkdir dir="${emma.coverage.merged.dir}" />
</target>
<target name="emma-turn-on" description="turns on EMMA instrumentation/reporting">
<property name="emma.enabled" value="true" />
<property name="emma.verbosity.level" value="verbose" />
</target>
<target name="emma-instrumentation-src" depends="emma-turn-on, emma-init" description="do EMMA's src instrumentation">
<emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}" >
<instr
instrpath="${build.src.dir}"
destdir="${emma.instr.src.dir}"
metadatafile="${emma.data.dir}/metadata-src.em"
merge="true"
mode="fullcopy"
>
<filter value="${emma.filter.src}" />
</instr>
</emma>
</target>
<target name="emma-instrumentation-test" depends="emma-turn-on, emma-init" description="do EMMA's test instrumentation">
<emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}" >
<instr
instrpath="${build.test.dir}"
destdir="${emma.instr.test.dir}"
metadatafile="${emma.data.dir}/metadata-test.em"
merge="true"
mode="fullcopy"
>
<filter value="${emma.filter.test}" />
</instr>
</emma>
</target>
<target name="run-emma-instrumentation" depends="emma-instrumentation-src, emma-instrumentation-test" />
<target name="emma-instrumentation" depends="emma-init, run-emma-instrumentation" description="do EMMA's merge instrumentation" />
<target name="emma-do-test" depends="emma-instrumentation" >
<junit printsummary="yes" haltonfailure="true" fork="true" >
<classpath>
<path refid="classpath.emma.run" />
</classpath>
<formatter type="plain" usefile="false" />
<batchtest todir="${emma.report.dir}" >
<fileset dir="${test.src.dir}" includes="**/*Test.java" />
</batchtest>
<jvmarg value="-Demma.coverage.out.file=${emma.runtime.coverage.data.file}" />
<jvmarg value="-Demma.coverage.out.merge=true" />
</junit>
<echo message="Emma Test Result : ${emma.report.dir}" />
<echo message="Emma file : ${emma.runtime.coverage.data.file}" />
</target>
<target name="emma-run-instrumentation-merge" depends="emma-do-test" description="do EMMA's instrumentation">
<emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}" >
<merge outfile="${emma.coverage.file}" >
<fileset dir="${emma.data.dir}" includes="*.em, *.ec" />
</merge>
</emma>
</target>
<target name="emma-run-report" depends="emma-run-instrumentation-merge" >
<emma enabled="${emma.enabled}" verbosity="${emma.verbosity.level}">
<report sourcepath="${src.dir}" depth="all" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100" >
<fileset dir="${emma.coverage.merged.dir}" >
<include name="*.emma" />
</fileset>
<xml outfile="${emma.report.dir}/coverage.xml" depth="all" columns="class,method,block,line,name" />
<txt outfile="${emma.report.dir}/coverage.txt" depth="all" columns="class,method,block,line,name" />
<html outfile="${emma.report.dir}/coverage.html" depth="all" columns="class,method,block,line,name" />
</report>
</emma>
</target>
<target name="run-emma" depends="emma-run-report" />
</project>
Output:
emma-run-instrumentation-merge:
[merge] [EMMA v2.0, build 5312 (2005/06/12 19:32:43)]
[merge] input data path:
[merge] {
[merge] C:\Temp\builds\Example\emma\report\data\metadata-src.em
[merge] C:\Temp\builds\Example\emma\report\data\metadata-test.em
[merge] }
[merge] processing input file [C:\Temp\builds\Example\emma\report\data\metadata-src.em] ...
[merge] loaded 40 metadata entries
[merge] processing input file [C:\Temp\builds\Example\emma\report\data\metadata-test.em] ...
[merge] loaded 3 metadata entries
[merge] 2 file(s) read and merged in 20 ms
[merge] merged metadata contains 43 entries
[merge] merged/compacted data written to [C:\Temp\builds\Example\emma\report\data\final\coverage-final.emma] {in 0 ms}
emma-run-report:
[report] [EMMA v2.0, build 5312 (2005/06/12 19:32:43)]
[report] input data path:
[report] {
[report] C:\Temp\builds\Example\emma\report\data\final\coverage-final.emma
[report] }
[report] source path:
[report] {
[report] D:\wkp\AppUtils\src
[report] }
[report] processing input file [C:\Temp\builds\Example\emma\report\data\final\coverage-final.emma] ...
[report] loaded 43 metadata entries
[report] 1 file(s) read and merged in 0 ms
[report] nothing to do: no runtime coverage data found in any of the data files
run-emma:
BUILD SUCCESSFUL
Total time: 7 seconds
OUTPUT WITH DEBUG:
emma-do-test:
[junit] Couldn't find junit/framework/TestCase.class
[junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar
[junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar
[junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar
[junit] Found D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar
fileset: Setup scanner in dir D:\wkp\AppUtils\libs with patternSet{ includes: [**/*.jar] excludes: [] }
Finding class junit.framework.Test
Loaded from D:\wkp\AppUtils\libs\junit-4.11.jar junit/framework/Test.class
Class java.lang.Object loaded from parent loader (parentFirst)
Class junit.framework.Test loaded from ant loader (parentFirst)
Finding class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl
Loaded from D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.class
Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror loaded from parent loader (parentFirst)
Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror$SummaryJUnitResultFormatterMirror loaded from parent loader (parentFirst)
Class java.lang.Throwable loaded from parent loader (parentFirst)
Finding class junit.framework.AssertionFailedError
Loaded from D:\wkp\AppUtils\libs\junit-4.11.jar junit/framework/AssertionFailedError.class
Class java.lang.AssertionError loaded from parent loader (parentFirst)
Class junit.framework.AssertionFailedError loaded from ant loader (parentFirst)
Class java.lang.ClassLoader loaded from parent loader (parentFirst)
Class org.apache.tools.ant.AntClassLoader loaded from parent loader (parentFirst)
Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror$JUnitTestRunnerMirror loaded from parent loader (parentFirst)
Class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask loaded from parent loader (parentFirst)
fileset: Setup scanner in dir D:\wkp\AppUtils\test with patternSet{ includes: [**/*Test.java] excludes: [] }
[junit] Implicitly adding D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar to CLASSPATH
[junit] Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
[junit] '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
[junit] '-Demma.coverage.out.merge=false'
[junit] '-classpath'
[junit] 'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
[junit] 'app.commons.enums.TypeFileSizeTest'
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=true'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
[junit] 'showoutput=false'
[junit] 'outputtoformatters=true'
[junit] 'logfailedtests=true'
[junit] 'logtestlistenerevents=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.enums.TypeFileSizeTest.txt'
[junit] 'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher3180808930350880484.properties'
[junit] 'propsfile=D:\wkp\AppUtils\ant\emma\junit6882722104357253846.properties'
[junit]
[junit] The ' characters around the executable and arguments are
[junit] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
'-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
'-Demma.coverage.out.merge=false'
'-classpath'
'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
'app.commons.enums.TypeFileSizeTest'
'filtertrace=true'
'haltOnError=false'
'haltOnFailure=true'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
'showoutput=false'
'outputtoformatters=true'
'logfailedtests=true'
'logtestlistenerevents=false'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.enums.TypeFileSizeTest.txt'
'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher3180808930350880484.properties'
'propsfile=D:\wkp\AppUtils\ant\emma\junit6882722104357253846.properties'
The ' characters around the executable and arguments are
not part of the command.
[junit] Running app.commons.enums.TypeFileSizeTest
[junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.026 sec
[junit] Implicitly adding D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar to CLASSPATH
[junit] Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
[junit] '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
[junit] '-Demma.coverage.out.merge=false'
[junit] '-classpath'
[junit] 'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
[junit] 'app.commons.utils.AppFileUtilsTest'
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=true'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
[junit] 'showoutput=false'
[junit] 'outputtoformatters=true'
[junit] 'logfailedtests=true'
[junit] 'logtestlistenerevents=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppFileUtilsTest.txt'
[junit] 'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher4273539226127863796.properties'
[junit] 'propsfile=D:\wkp\AppUtils\ant\emma\junit7675821937325699249.properties'
[junit]
[junit] The ' characters around the executable and arguments are
[junit] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
'-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
'-Demma.coverage.out.merge=false'
'-classpath'
'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
'app.commons.utils.AppFileUtilsTest'
'filtertrace=true'
'haltOnError=false'
'haltOnFailure=true'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
'showoutput=false'
'outputtoformatters=true'
'logfailedtests=true'
'logtestlistenerevents=false'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppFileUtilsTest.txt'
'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher4273539226127863796.properties'
'propsfile=D:\wkp\AppUtils\ant\emma\junit7675821937325699249.properties'
The ' characters around the executable and arguments are
not part of the command.
[junit] Running app.commons.utils.AppFileUtilsTest
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.239 sec
[junit] Implicitly adding D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar to CLASSPATH
[junit] Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
[junit] '-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
[junit] '-Demma.coverage.out.merge=false'
[junit] '-classpath'
[junit] 'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
[junit] 'app.commons.utils.AppSystemUtilsTest'
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=true'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
[junit] 'showoutput=false'
[junit] 'outputtoformatters=true'
[junit] 'logfailedtests=true'
[junit] 'logtestlistenerevents=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppSystemUtilsTest.txt'
[junit] 'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher2828995806384576666.properties'
[junit] 'propsfile=D:\wkp\AppUtils\ant\emma\junit7199116178610816128.properties'
[junit]
[junit] The ' characters around the executable and arguments are
[junit] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\App\Java\jdk1.7.0_79\jre\bin\java.exe' with arguments:
'-Demma.coverage.out.file=c:\temp\builds\AppUtils\emma\report\data\coverage.ec'
'-Demma.coverage.out.merge=false'
'-classpath'
'c:\temp\builds\AppUtils\emma\target\src;c:\temp\builds\AppUtils\emma\target\test;c:\temp\builds\AppUtils\test;c:\temp\builds\AppUtils\src;D:\wkp\AppUtils\libs\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\wkp\AppUtils\libs\joda-time-2.1.jar;D:\wkp\AppUtils\libs\junit-4.11.jar;D:\wkp\AppUtils\libs\mockito-all-1.9.5.jar;D:\wkp\AppUtils\ant\emma\lib\emma.jar;D:\wkp\AppUtils\ant\emma\lib\emma_ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-launcher.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit.jar;D:\App\eclipse-kepler-x64-V3.a\plugins\org.apache.ant_1.8.4.v201303080030\lib\ant-junit4.jar'
'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
'app.commons.utils.AppSystemUtilsTest'
'filtertrace=true'
'haltOnError=false'
'haltOnFailure=true'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
'showoutput=false'
'outputtoformatters=true'
'logfailedtests=true'
'logtestlistenerevents=false'
'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter,c:\temp\builds\AppUtils\emma\report\TEST-app.commons.utils.AppSystemUtilsTest.txt'
'crashfile=D:\wkp\AppUtils\ant\emma\junitvmwatcher2828995806384576666.properties'
'propsfile=D:\wkp\AppUtils\ant\emma\junit7199116178610816128.properties'
The ' characters around the executable and arguments are
not part of the command.
[junit] Running app.commons.utils.AppSystemUtilsTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.019 sec
[echo] Emma Test Result : c:\temp\builds\AppUtils\emma\report
[echo] Emma file : c:\temp\builds\AppUtils\emma\report\data\coverage.ec
You get this error when you use wrong command to generate the report. Most of the online tutorial is advocating the wrong(may by old) command, even I got this error when I used below command to generate the report:
{JAVA_HOME}\jre\lib\ext>java -cp emma.jar emma report -r html -in coverage.em, {ALFRESCO_HOME}\coverage.ec
EMMA: processing input files ...
EMMA: 1 file(s) read and merged in 60 ms
EMMA: nothing to do: no runtime coverage data found in any of the data files
Correct usage of the command is(Mark there is extra "-in" in command):
{JAVA_HOME}\jre\lib\ext>java -cp emma.jar emma report -r txt,html -in {JAVA_HOME}\jre\lib\ext\coverage.em -in C:\t1_tempSetup\Alfresco\coverage.ec
EMMA: processing input files ...
EMMA: 2 file(s) read and merged in 70 ms EMMA: writing [txt] report to [{JAVA_HOME}\jre\lib\ext\coverage.txt] ...
EMMA: writing [html] report to [{JAVA_HOME}\jre\lib\ext\coverage\index.html]
The first time that I ran this, this error was occurring::
[junit] Running app.commons.enums.TypeFileSizeTest
[junit] Testsuite: app.commons.enums.TypeFileSizeTest
[junit] Tests run: 8, Failures: 0, Errors: 8, Time elapsed: 0.04 sec
[junit] Tests run: 8, Failures: 0, Errors: 8, Time elapsed: 0.04 sec
[junit] Testcase: POS_TEST_CONVERT_TO_EB took 0 sec
[junit] Caused an ERROR
[junit] Expecting a stackmap frame at branch target 11
[junit] Exception Details:
[junit] Location:
[junit] app/commons/enums/TypeFileSize.<init>(Ljava/lang/String;ILjava/lang/Integer;)V #4: ifnonnull
[junit] Reason:
[junit] Expected stackmap frame at this location.
[junit] Bytecode:
[junit] 0000000: b200 8c59 c700 0757 b800 9605 323a 042a
[junit] 0000010: 2b1c b700 62a 2db5 0007 1904 0304 54b1
[junit] 0000020:
Actually I made a very bad supposition that I was doing it in the wrong way...
After a few days thinking and wasting some time to understand the problem..
I found the solution: add an argument in the VM:
(Sorry I lost the reference..)
<jvmarg value="-XX:-UseSplitVerifier" />
-In the end I just need to modify my 'emma-do-test' task:
<target name="emma-do-test" depends="emma-instrumentation" >
<junit printsummary="withOutAndErr" haltonfailure="true" fork="true" >
<classpath>
<path refid="classpath.emma.run" />
</classpath>
<formatter type="plain" usefile="false" />
<batchtest todir="${emma.report.dir}" >
<fileset dir="${test.src.dir}" includes="**/*Test.java" />
</batchtest>
<jvmarg value="-XX:-UseSplitVerifier" />
<jvmarg value="-Demma.coverage.out.file=${emma.runtime.coverage.data.file}" />
<jvmarg value="-Demma.coverage.out.merge=false" />
</junit>
<echo message="Emma Test Result : ${emma.report.dir}" />
<echo message="Emma file : ${emma.runtime.coverage.data.file}" />
</target>

Source and Test "source" directories - how can I run tests from Test against Source

I've got a Java project which has a 'src' directory for code directly related to my project, and a 'test' directory which is JUnit tests that run against code in the 'src' directory. The directory structures are like this:
ROOT/src/com/mycompany/decoders/qDecoder/.....
ROOT/test/com/mycompany/decoders/qDecoder/.....
Both directories have the exact same package structure.
The following is the target and related JUnit info:
<property name="src_classes_dir" value="./bin"/>
<property name="test_classes_dir" value="./binTest"/>
<path id="junit.classpath">
<pathelement location="${src_classes_dir}"/>
<pathelement location="${test_classes_dir}"/>
<pathelement location="${CommonJarPath}/JUnit/junit.jar"/>
<pathelement location="${CommonJarPath}/JavaMail/mailapi.jar"/>
<pathelement location="${CommonJarPath}/JavaMail/smtp.jar"/>
<pathelement location="${CommonJarPath}/CommonsLang3/commons-lang3.jar"/>
<pathelement location="${CommonJarPath}/JDBC/inetsoftware/merlia/8.0.2/Merlia.jar"/>
<pathelement location="${CommonJarPath}/JodaTime/joda-time.jar"/>
</path>
<property name="test_dir" value="./test"/>
<target name="junit" description="Run JUnit tests" depends="compile_source, compile_test">
<junit fork="yes" haltonfailure="yes" haltonerror="yes" showoutput="yes">
<formatter type="plain" usefile="no"/>
<classpath refid="junit.classpath"/>
<batchtest>
<fileset dir="${test_dir}" />
</batchtest>
</junit>
</target>
So, my test files (*.java) are in ${test_dir}. The test classes are in the ${test_classes_dir} and the tested classes are in ${src_classes_dir}. Both are listed in the junit.classpath reference.
All of the targets are completed, 'clean', 'prep', 'src_compile', and 'test_compile' up to the 'junit' target, then I get a ClassNotFoundException on the very first test AMCiBitsTest. So it knows about the test, but for some reason cannot find its class.
Here's the exception trace:
junit:
[junit] Testsuite: com.amci.util.AMCiBitsTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]
[junit] Caused an ERROR
[junit] com.amci.util.AMCiBitsTest
[junit] java.lang.ClassNotFoundException: com.amci.util.AMCiBitsTest
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:190)
[junit]
I'm stumped. What am I doing wrong? Why can't this run the AMCiBitsTest test and all of the other tests?
I've fixed it. Suffice it to say that I made a syntax error in my build file, and what is posted above actually DOES WORK. My apologies, and thanks for your questions and your time.

Ant build Error: when I try to run This error will generate

root#ubuntu:/home/dj/workspace/TestProject# ant test
Buildfile: /home/dj/workspace/TestProject/build.xml
test:
[junit] Testsuite: TestProject
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]
[junit] Caused an ERROR
[junit] TestProject
[junit] java.lang.ClassNotFoundException: TestProject
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:169)
[junit]
BUILD FAILED
/home/dj/workspace/TestProject/build.xml:17: Test TestProject failed
Total time: 0 seconds
<project name="TestProject" basedir="." default="" >
<property name="src" value="./src" />
<property name="lib" value="./lib" />
<property name="classes" value="./classes" />
<property name="ant.project.name" value="com.megacorp.projx.util" />
<path id="test.classpath">
<pathelement location="${classes}" />
<pathelement location="usr/junit.jar" />
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="test">
<junit fork="yes" haltonfailure="yes">
<test name="${ant.project.name}" />
<formatter type="plain" usefile="false" />
<classpath refid="test.classpath" />
</junit>
</target>
This is wrong:
<test name="${ant.project.name}" />
Here you should set the name of the junit-class you want to test, and not the name of the ant project.
E.g.:
<test name="myorg.MyTest" />
Links:
Documentation for junit task: have a look at the examples at the Bottom

How do I have ant list all failed jUnit tests?

I've seen a couple of posts about this but none provide the solution I'm looking for. I have ant set up so when it runs our tests we get the following output (which I like):
[junit] Running net.windward.document.test.TestTab
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.59 sec
[junit] Running net.windward.document.test.TestTableAttributes
[junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.604 sec
... continues for 300+ tests ...
But then at the end I just get "some tests failed". Is there some way to have it then list out the filenames of the tests that have failed?
thanks - dave
build.xml:
<junit printsummary="yes" errorProperty="test.failed" failureProperty="test.failed" >
<formatter type="plain" />
<classpath path="${classpath.run.test}"/>
<batchtest fork="yes" todir="${reports}">
<fileset dir="${src}">
<include name="**/test/**/Test*.java" />
<exclude name="**/_*/**/*.java" />
</fileset>
</batchtest>
</junit>
<fail if="test.failed" message="one or more unit tests failed"/>
<echo>unit tests all passed</echo>
<antcall target="testinternal"/>
</target>
Read chapter 4 of "Java Development with Ant": http://www.manning-source.com/books/hatcher/hatcher_ch04.pdf
You can use
<formatter type="xml" />
to generate an xml output of the tests. This can be converted to html to view it in a browser after all tests have run using the ant task junitreport. You can also import the xml file into eclipse if you use it.

Resources