此步骤调用 JUnit 测试用例,这些用例不需要运行时资源(如数据源等)。我们假定您已经获得了运行此步骤所需的此类测试用例。清单 7 说明了如何在工作区调用所有 JUnite 测试用例,并假设全部都以单词“Test”作为结尾。当然,如果命名约定不同,则可以对此进行相应的更改。
清单 7. 调用 JUnit 测试用例
<target name="predeptests" description="Invoke pre-deployment JUnit test cases">
<!-- Run JUnit and print a summary when done. -->
<junit printsummary="yes" haltonfailure="no">
<classpath>
<!--
Set the class path to include all needed classes that are used by the JUnit test cases.
-->
</classpath>
<!-- Generate reports in an XML format -->
<formatter type="xml" />
<!-- Run a batch of JUnit test cases and generate reports to the report directory. -->
<batchtest fork="yes" todir="${report.dir}">
<fileset dir="${workspace.dir}/">
<!-- Include all .java files that end with "Test" -->
<include name="**/*Test.java" />
</fileset>
</batchtest>