2008-11-29 31 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> 
相關問題