Given the following build.xml: <project name="x" default="x"> <target name="x"> <javac srcdir="." classpath="junit-4.1.jar" /> <junit fork="true" timeout="100"> <test name="x" /> <classpath> <pathelement location="junit-4.1.jar" /> </classpath> <formatter type="brief" usefile="false" /> </junit> </target> </project> x.java: import org.junit.Test; public class x { @Test public void foo () { while (true) ; } } And junit-4.1.jar in the directory, when executing the build, the following error occurs: [bmaurer@omega x]$ ../ant/apache-ant-1.7alpha/bin/ant Buildfile: build.xml x: BUILD FAILED /home/bmaurer/x/build.xml:4: Using loader AntClassLoader[/home/bmaurer/x/junit-4.1.jar:/home/bmaurer/ant/apache-ant-1.7alpha/lib/ant-launcher.jar:/home/bmaurer/ant/apache-ant-1.7alpha/lib/ant.jar:/home/bmaurer/ant/apache-ant-1.7alpha/lib/ant-junit.jar] on class org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter: java.lang.NoClassDefFoundError: junit/framework/TestListener Total time: 0 seconds
Have you made sure that junit.jar and the class files for the junit task (ant-junit.jar) have been made available from the same source? (from the manual:) Note: You must have junit.jar and the class files for the <junit> task in the same classpath. You can do one of: 1. Put both junit.jar and the optional tasks jar file in ANT_HOME/lib. 2. Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable. 3. Do neither of the above, and instead, specify their locations using a <classpath> element in the build file. See the FAQ for details. Your build file only specifies the junit.jar file in the classpath, and your ANT_HOME/lib probably only has ant-junit.jar. Please make the two jar files available the same way, and report if it still does not work.
This is ant 1.7, so I am doing one of the new options added: Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the <classpath> passed to <junit>. (since Ant 1.7) JUnit works fine *except* when there is a timeout. In that case, it will display this error. I assume that the timeout codepath has not been updated for the 1.7 behavior.
I have applied a fix to HEAD, please verify
This is better. However, in the xml file, I get: <testcase classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$1" name="unknown" time="0.01"> Ideally, this would be the name of the failing test, or at least some better indication of what actually happened.
The output has been enhanced to include (only!) the testcase that was running during the timeout / unexpected termination. Please next time use a different bug report to report another issue / request, and not reuse an existing one, it makes life easier when tracking issues. output now: <testcase classname="x" name="foo" time="0.0"> <error message="Timeout occurred. Please note the time in the report does not reflect the time until the timeout." type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedErro r: Timeout occurred. Please note the time in the report does not reflect the time until the timeout. </error> </testcase> and was: <testcase classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$1" name="unknown" time="0.0"> <error message="Timeout occurred" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedErro r: Timeout occurred. </error> </testcase>