<target name="component-test"
if="Junit.present"
depends="junit-present,compile-tests">
<mkdir dir="${testreportdir}"/>
<junit dir="./" failureproperty="test.failure"
printSummary="yes"
fork="true" haltonerror="true">
<sysproperty key="basedir" value="."/>
<formatter type="xml"/>
<formatter usefile="false" type="plain"/>
<classpath>
<path refid="build.classpath"/>
<pathelement path="${testclassesdir}"/>
<pathelement path="${classesdir}"/>
</classpath>
<batchtest todir="${testreportdir}">
<fileset dir="test">
<include name="**/ComponentTestSuite.java"/>
</fileset>
</batchtest>
</junit>
</target>
理想情况下,还需要有调用单元测试和系统测试的任务。最后,在想要运行整个测试套件时,应该创建一个依赖于所有三种测试种类的第四项任务,如清单 3 中如示:
<target name="test-all" depends="unit-test,component-test,system-test"/>
创建定制 TestSuite 是实现测试分类的一个快速解决方案。这个方法的缺点是:一旦创建新测试,就必须通过编程将它们添加到适当的 TestSuite 中,这很痛苦。为每种测试创建定制目录更具扩展性,且允许不 经过重新编译就添加新的经过分类的测试。
我发现,用 JUnit 实现测试分类最简单的方法是将测试在逻辑上划分为与其测试类型相应的特定目录。使用这项技术,所有的单元测试将驻留在一个 unit 目录中,所有的组件测试将驻留在一个 component 目录中,依此类推。
例如,在一个保存所有未分类测试的 test 目录中,可以创建三个新的子目录,如清单 4 所示:
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/










