6.可以通過File-export-Ant的方式,將項目轉(zhuǎn)化為Ant項目,會自動生成build.xml,然后修改代碼為:
<project name="TestNGTest" default="testoutput" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.8.jar" />
</classpath>
</taskdef>
<property name="testoutputdir" location="testoutput" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<property name="basedir" value="D:/workspace/TestNGSimple/" />
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testoutputdir}" />
<pathelement location="${srcdir}" />
</path>
<target name="clean">
<delete dir="${basedir}/bin" />
</target>
<target name="compile" depends="clean">
<mkdir dir="${basedir}/bin" />
<javac srcdir="${srcdir}" encoding="UTF-8" destdir="${basedir}/bin" verbose="${full-compile}" classpathref="classpath.test" includeantruntime="off" debug="on" debuglevel="lines,vars,source" />
</target>
<path id="classes">
<fileset dir="${libdir}" includes="*jar"/>
<fileset dir="${libdir}" includes="*zip"/>
<pathelement location="${basedir}/bin/"/>
</path>
<target name="runtest" depends="compile">
<testng outputdir="${testoutputdir}" classpathref="classes" delegateCommandSystemProperties="true">
<xmlfileset dir="${srcdir}" includes="testng.xml" />
</testng>
</target>
<target name="testoutput" depends="runtest">
<xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
<param name="testNgXslt.outputDir" expression="D:/workspace/TestNGSimple/testoutput/" />
<classpath refid="classpath.test" />
</xslt>
</target>
</project>
7. 右鍵 build.xml 文件,Run as -- Ant build
8. testoutput中 生成測試美化后的報告
注意:
1.
<project name="TestNGTest" default="testoutput" basedir=".">
default=“testoutput”,如果不需要美化的報告,則改為runtest
2.注意classes 的配置,然后引入到runtest的配置中,否則報找不到class的異常。
<path id="classes">
<fileset dir="${libdir}" includes="*jar"/>
<fileset dir="${libdir}" includes="*zip"/>
<pathelement location="${basedir}/bin/"/>
</path>
<target name="runtest" depends="compile">
<testng outputdir="${testoutputdir}" classpathref="classes" delegateCommandSystemProperties="true">
<xmlfileset dir="${srcdir}" includes="testng.xml" />
</testng>
</target>
3.testng-results.xml在路徑(testng-xslt-1.1.2-master estsingle)下
<target name="testoutput" depends="runtest">
<xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
<param name="testNgXslt.outputDir" expression="D:/workspace/TestNGSimple/testoutput/" />
<classpath refid="classpath.test" />
</xslt>
</target>