JUnit失败,但没有测试报告失败



我在Windows XP的命令行上使用Ant运行JUnit测试。

在某些运行中,在运行所有测试的中途,我将得到一条指向特定测试类的BUILD FAILED消息,但是在控制台输出和XML文件中,该类中的所有测试都报告为已通过。

类不包含非确定性,也不应该有任何副作用。也没有理由让它耗尽内存。

是什么导致了这些奇怪的构建失败?


:

我怀疑这将是有用的,但这里是运行失败时的结束(修改目录和包名以匿名):

C:projer20rr> ant clean build test
<snip/>
[junit] Running com.example.PathUTest
[junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 7.5 sec
BUILD FAILED
C:projer20commonbuild.xml:385: The following error occurred while executing this line:
C:projer20rrbuild.xml:58: Test com.example.PathUTest failed

更新2 :

我终于设法使失败发生在启用了-verbose的情况下。下面是堆栈跟踪(手工复制):

BUILD FAILED
C:projer20commonbuild.xml:385: The following error occurred while executing this line:
C:projer20rrbuild.xml:58: Test com.example.PathUTest failed
    at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:541)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:418)
    at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
    at org.apache.tools.ant.Main.runBuild(Main.java:698)
    at org.apache.tools.ant.Main.startAnt(Main.java:199)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: C:projer20rrbuild.xml:58: Test com.example.PathUTest failed
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.actOnTestResult(JUnitTask.java:1712)
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:820)
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.executeOrQueue(JUnitTask.java:1657)
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:764)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
    ... 17 more
--- Nested Exception ---
C:projer20rrbuild.xml:58 Test com.example.PathUTest failed
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.actOnTestResult(JUnitTask.java:1712)
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:820)
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.executeOrQueue(JUnitTask.java:1657)
    at org.apache.tools.ant.taskdefs.optionl.junit.JUnitTask.execute(JUnitTask.java:764)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.perform(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
    at org.apache.tools.ant.tskdefs.CallTarget.execute(CallTarget.java:105)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Source Unknown)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
    at org.apache.tools.ant.Main.runBuild(Main.java:698)
    at org.apache.tools.ant.Main.startAnt(Main.java:199)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 1 minute 27 seconds
下面是相关的Ant目标:
<target name="test">
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="../buildsupport/lib/ant-contrib-1.0b3.jar"/>
        </classpath>
    </taskdef>
    <!-- line 58 is the next line -->
    <junit printsummary="yes" fork="yes" haltonfailure="yes" dir="${test-dir}" showoutput="yes">
        <jvmarg value="-Xmx10200M"/>
        <jvmarg value="-Xms600M"/>
        <jvmarg value="-server"/>
        <jvmarg value="-Dlog4j.configuration=file:log4j.xml"/>
        <jvmarg value="-XX:CompileCommand=exclude,com.example.GtaCore,expandLabel"/>
        <env key="LD_LIBRARY_PATH" path="${env.LD_LIBRARY_PATH}:${test-dir}/native_lib"/>
        <jvmarg value="-Djava.library.path=./native_lib"/>
        <formatter type="xml"/>
        <classpath>
            <!-- classpath items -->
        </classpath>
        <batchtest>
            <fileset includes="**/*Test.class" excludes="**/*$$*.class"/>
        </batchtest>
    </junit>
    <junitreport>
        <!-- config -->
    </junitreport>
    <echo> finished suite</echo>
</target>

可能原因及解决方法

我们发现,在我们调用的代码的深处,正在显示一个错误调试GUI,该GUI在另一个线程中运行。自从禁用了这个GUI的显示,我们再也没有看到这个问题了。

也许在rrbuild.xml(你有2个构建文件)第58行有

<fail message="Test com.example.PathUTest failed"/>

相关内容

  • 没有找到相关文章

最新更新