2011-08-02 62 views
1

因此,我使用JUnit設置了自動迴歸測試,現在構建腳本設置爲調用TestSuite,它將一堆不同的測試打包到TestSuite中並返回它。Ant,JUnit和TestSuite

構建文件:

<target name="test-perform-check" depends="test-compile"> 
     <junit printsummary="yes" fork="yes" haltonfailure="no"> 
      <classpath path ="${mypath}" /> 
      <jvmarg value="-Djava.ext.dirs=${extstar};${extpathextended};" /> 
        <jvmarg value="-Dmipav=${mipav};" /> 
      <sysproperty key="mipav" value="${mipav}"/> 
      <formatter type="xml"/> 
      <formatter type="plain" usefile="false"/> 
      <test name="test.JTest"/> 
     </junit> 
    </target> 

JTest.java:

class JTest extends TestSuite { 

    public static Test suite() { 
     // set up a bunch of stuff 
     TestSuite suite = new TestSuite(); 
     suite.addTest(new VolumeCompare()); 
     suite.addTest(new VolumeCompare()); 
     suite.addTest(new VolumeCompare()); 
     suite.addTest(new FileExistence()); 
     // do some other stuff 
     return suite; 
    } 
} 

輸出:

[junit] Testcase: null took 0.002 sec 
[junit]  FAILED 
[junit] null 
[junit] junit.framework.AssertionFailedError 
[junit] 
[junit] Testcase: null took 0 sec 
[junit]  FAILED 
[junit] null 
[junit] junit.framework.AssertionFailedError 
[junit] 
[junit] Testcase: null took 0.002 sec 
[junit]  FAILED 
[junit] null 
[junit] junit.framework.AssertionFailedError 
[junit] 
[junit] Testcase: null took 0 sec 
[junit]  FAILED 
[junit] null 
[junit] junit.framework.AssertionFailedError 
[junit] 
[junit] Test test.JTest FAILED 

我的問題是 - 什麼,我需要在buildscript改變,使螞蟻運行測試正確嗎?

編輯:

VolumeCompare.java:

public class VolumeCompare extends TestCase { 
    public VolumeCompare (...) { 
     // ctor 
    } 
    @Test 
    public void testVolume() { 
     // this print statement is never reached 
     System.out.println("testing volume"); 
     // compare volumes here 
    } 
} 
+0

你可以發佈你的'VolumeCompare.java'文件嗎? –

+0

已發佈。如果我設法修復它,我會把它扔在那裏。 – ellioth

回答

0

junit task documentation,我想測試的屬性具有與包含單個測試(而不是一套房)一類使用。也許你可以使用一種模式來問螞蟻在一個給定的包運行每一個測試,像這樣:

<batchtest fork="yes" todir="${reports.tests}"> 
    <fileset dir="${src.tests}"> 
    <include name="**/*Test*.java"/> 
    <exclude name="**/AllTests.java"/> 
    </fileset> 
    </batchtest> 
+0

是的,但我不想*螞蟻立即運行所有測試。在我運行測試之前,我有一堆東西要做(緊縮很多數字),並且我不想在完成之前返回TestSuite。 – ellioth

+0

哦,對,這就是你'設置一堆東西'的意思,對不起。你總是可以選擇設置一個螞蟻任務來完成這個數字斬波,然後讓你的測試任務依賴於這個數字計算任務 - 當然這取決於測試類如何使用這個數字處理...你通過數據到你的測試類ctor?或者它存儲在數據庫/文件? – phtrivier

+0

好吧,所以我發現其他的文章與你幾乎一樣(http://opensource-soa.blogspot.com/2008/07/how-to-run-junit-test-suite-from-ant.html) 。所以也許這個問題實際上是在你自己的測試中 - 但很難說你發佈了什麼... – phtrivier

0

當使用一個TestSuite你的測試用例一次添加到您的套房一個測試用例,你的語法看起來應該更像這樣:

suite.addTest(new VolumeCompare("testCase1")); 
suite.addTest(new VolumeCompare("testCase2")); 
suite.addTest(new VolumeCompare("testCase3")); 

基本上你沒有通過測試的名稱來運行,所以它試圖運行「null」並失敗。