工具:Eclipse、Testng、Reportng、Ant
场景:通过Ant执行Testng用例,并输出Reportng报告
1、编写ant脚本
<?xml version="1.0"?>
<project name="MySelenium" default="run" basedir=".">
<echo message="import libs" />
<echo>Java-Home: ${java.home}</echo>
<echo>Java-Version: ${java.version}</echo>
<property name="src.dir" value="src est" />
<property name="dest.dir" value="build" />
<property name="dest.report" value="report" />
<path id="run.classpath">
<fileset dir="${basedir}">
<include name="lib/*.jar" />
</fileset>
</path>
<taskdef name="testng" classname="com.beust.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.9.9.jar"/>
</classpath>
</taskdef>
<target name="clean">
<delete dir="${dest.dir}" />
</target>
<target name="compile" depends="clean">
<echo message="mkdir" />
<mkdir dir="${dest.dir}" />
<javac target="1.7" srcdir="${src.dir}" destdir="${dest.dir}" encoding="UTF-8" debug="on" includeAntRuntime="false" >
<classpath refid="run.classpath" />
</javac>
</target>
<path id="runpath">
<path refid="run.classpath" />
<pathelement location="${dest.dir}" />
</path>
<target name="run" depends="compile">
<testng classpathref="runpath" outputDir="${dest.report}" haltOnFailure="true" useDefaultListeners="false" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,org.testng.reporters.FailedReporter">
<!--<testng classpathref="runpath" outputDir="${dest.report}" haltOnFailure="true" useDefaultListeners="true" >-->
<xmlfileset dir="${basedir}" includes="testng.xml" />
<jvmarg value="-ea" />
</testng>
</target>
</project>
2、引入需要的jar包
testng输出报告
好将下面的jar包都引入,不然会疯掉的,会一个个报错提示你
(其中jxl-2.6.12.jar读取excel,东面j-1.6.jar读取xml,没有用到的可以不加)