Bug 39946 - NoClassDefFoundError when timeout set and junit.jar loaded via <classpath>
Summary: NoClassDefFoundError when timeout set and junit.jar loaded via <classpath>
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: nightly
Hardware: Other other
: P2 enhancement (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-02 18:23 UTC by Ben Maurer
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Maurer 2006-07-02 18:23:14 UTC
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
Comment 1 J.M. (Martijn) Kruithof 2006-07-02 20:49:26 UTC
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.
Comment 2 Ben Maurer 2006-07-02 21:53:49 UTC
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.
Comment 3 J.M. (Martijn) Kruithof 2006-07-03 20:21:12 UTC
I have applied a fix to HEAD, please verify
Comment 4 Ben Maurer 2006-07-03 21:55:13 UTC
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.
Comment 5 J.M. (Martijn) Kruithof 2006-07-08 21:25:40 UTC
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>