2011-08-24 56 views
0

假设您有一个test目录,其中包含每个包含jUnit测试的包。通过ANT运行jUnit测试,需要澄清

在此设置中,使用ANT,您将如何“运行所有测试?”

假设我的JUnit有

<target name="test" depends="compileTest"> 
    <junit fork="yes" printsummary="yes" haltonfailure="no"> 

     <classpath location="${bin}" /> 

     <formatter type="plain" /> 
     <test name="_com.??.project.alltests.MyTests" /> 

    </junit> 
</target> 

其中,MyTests有

@RunWith(Suite.class) 
@Suite.SuiteClasses({ _ThisTest.class, _ThatTest.class }) 
public class OCTTests { 

} 

_ThisTest本身含有一些测试..

是否有可能在ant脚本的目的,以避免这种只需简单地说:“运行您在此目录中找到的所有测试”

回答

1

查看junit任务的nested batchtest元素。 您可以在junit task文档页面上找到以下示例:

<junit printsummary="yes" haltonfailure="yes"> 
    <classpath> 
    <pathelement location="${build.tests}"/> 
    <pathelement path="${java.class.path}"/> 
    </classpath> 

    <formatter type="plain"/> 

    <test name="my.test.TestCase" haltonfailure="no" outfile="result"> 
    <formatter type="xml"/> 
    </test> 

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