6.可以通过File-export-Ant的方式,将项目转化为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>