1、在Ant中設置如下:
<target name="run_tests">
<testng classpathref="classpath.main"
failureproperty="test.failed">
<!--此目錄下的所有TestNG的XML文件,使用*號表示此目錄下所有 -->
<xmlfileset dir="${suite.dir}">
<include name="*.xml"/>
</xmlfileset>
</testng>
<!--TestNG執行完畢後,根據輸出的testng-results.xml文件,按照testng-results.xsl的設定生成html格式的測試報告 -->
<echo taskname="OutputReport" message="start output report" />
<xslt in="${test-output.dir}/testng-results.xml" style="${testNgXslt.dir}/config/testng-results.xsl" out="${testNgXslt.dir}/out/${CURTIME}/index.html">
<param name="testNgXslt.outputDir" expression="${testNgXslt.dir}/out/${CURTIME}"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
<classpath refid="classpath.main"/>
</xslt>
</target>
在上述配置中,${testNgXslt.dir}/out/${CURTIME}表示測試報告輸出的目錄,${CURTIME}是根據測試執行時間標識,按照年月日時分秒格式。如下:
<tstamp>
<format property="CURTIME" pattern="yyyyMMddHHmmss" locale="us"/>
</tstamp>