2010-05-07 94 views
15

我有很多的测试,在下面的JUnit任务失败。Junit的Ant任务,输出堆栈跟踪

<target name="test-main" depends="build.modules" description="Main Integration/Unit tests"> 
     <junit fork="yes" 
       description="Main Integration/Unit Tests" 
       showoutput="true" 
       printsummary="true" 
       outputtoformatters="true"> 
      <classpath refid="test-main.runtime.classpath"/> 
      <batchtest filtertrace="false" todir="${basedir}"> 
       <fileset dir="${basedir}" includes="**/*Test.class" excludes="**/*MapSimulationTest.class"/> 
      </batchtest> 
     </junit> 
    </target> 

如何告诉Junit输出每个测试的错误,以便我可以查看堆栈跟踪并调试问题。

回答

8

答案是在标签中添加的标签。

<target name="test-main" depends="build.modules" description="Main Integration/Unit tests"> 
     <junit fork="yes" 
       description="Main Integration/Unit Tests" 
       showoutput="true" 
       printsummary="true" 
       outputtoformatters="true"> 
      <classpath refid="test-main.runtime.classpath"/> 
      <batchtest filtertrace="false"> 
       <fileset dir="${basedir}/out/test/common" includes="**/*Test.class" excludes="**/*MapSimulationTest.class"/> 
       <fileset dir="${basedir}/out/test/test-simulation" includes="**/*Test.class" excludes="**/*MapSimulationTest.class"/> 
      </batchtest> 
      <formatter type="brief" usefile="false"/> 
     </junit> 
    </target> 
17

你需要格式化任务添加为batchtest任务的孩子(还不如junit任务的直接子)

格式的语法是:

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

type可以是plain之一,brief,或xmlfailure

usefile="false"要求Ant来输出发送到控制台。

向下滚动到“格式化”在http://ant.apache.org/manual/Tasks/junit.html更多细节H4。

+1

至少有蚂蚁1.9.0,您还可以添加格式为junit任务的孩子。如果您有多个批处理任务,这将会很有帮助。 – 2013-04-16 14:12:19