2008-11-29 48 views
14

我正在使用Junit 4.4和Ant 1.7。如果测试用例失败并出现错误(例如,因为某个方法引发了意外的异常),我没有得到有关错误的详细信息。JUnit没有提供关于“错误”的信息

我的build.xml文件看起来是这样的:

<target name="test" depends="compile"> 
<junit printsummary="withOutAndErr" filtertrace="no" fork="yes" haltonfailure="yes" showoutput="yes"> 
    <classpath refid="project.run.path"/> 
    <test name="a.b.c.test.TestThingee1"/> 
    <test name="a.b.c.test.NoSuchTest"/> 
</junit> 
</target> 

当我运行 “蚂蚁测试” 它说,(例如)2测试运行,0失败,1个错误。它没有说“没有NoSuchTest这样的测试”,尽管这是完全合理的,并且让我找出错误的原因。

谢谢!

-Dan

回答

31

想通了:)

我需要添加JUnit的块内的 “格式化”。

<formatter type="plain" usefile="false" /> 

什么是PITA。

-Dan

+0

+1我只是有这个错误,这工作完美。谢谢! – 2010-05-04 17:11:27

6

如果你将有很多的测试,还有你可能要考虑两个变化:

  1. 运行所有测试,而不是在第一个错误
  2. 停止
  3. 创建一个显示所有的测试报告结果

而且它很容易与junitreport做任务:

<target name="test"> 
    <mkdir dir="target/test-results"/> 
    <junit fork="true" forkmode="perBatch" haltonfailure="false" 
      printsummary="true" dir="target" failureproperty="test.failed"> 
     <classpath> 
      <path refid="class.path"/> 
      <pathelement location="target/classes"/> 
      <pathelement location="target/test-classes"/> 
     </classpath> 
     <formatter type="brief" usefile="false" /> 
     <formatter type="xml" /> 
     <batchtest todir="target/test-results"> 
      <fileset dir="target/test-classes" includes="**/*Test.class"/> 
     </batchtest> 
    </junit> 

    <mkdir dir="target/test-report"/> 
    <junitreport todir="target/test-report"> 
     <fileset dir="target/test-results"> 
      <include name="TEST-*.xml"/> 
     </fileset> 
     <report format="frames" todir="target/test-report"/> 
    </junitreport> 

    <fail if="test.failed"/> 
</target>