2011-08-02 66 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”并失败。