ant+maven+testNG
1.工程目录:
jcommander.jar和commons-codec-1.10.jar架包当前通过ant+maven下载有问题,先直接将这两个架包放入lib
2.build.xml文件
<?xml version="1.0" encoding="UTF-8" ?> <project name="httpClient_first" basedir="." default="regression" xmlns:artifact="urn:maven-artifact-ant"> <property name="maven.ant.tasks.jar" value="${basedir}/maven-ant-tasks-2.1.3.jar" /> <property name="src" value="src"/> <property name="dest" value="build"/> <property name="testng.dir" value="${basedir}\lib"/> <property name="testng.output.dir" value="${basedir}\test-output"/> <target name="downJar" depends="init" description="下载maven项目依赖jar"> <echo message="*****初始化,下载maven库****"/> <path id="maven-ant-tasks.classpath" path="${maven.ant.tasks.jar}"/> <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" classpathref="maven-ant-tasks.classpath"/> <artifact:pom id="maven.project" file="pom.xml"/> <artifact:dependencies settingsfile="D:/soft/apache-maven-3.6.1/conf/settings.xml" pathId="maven.classpath" filesetid="maven.fileset"> <pom refid="maven.project"/> </artifact:dependencies> <copy todir="${basedir}/lib"> <fileset refid="maven.fileset"/> <!-- This mapper strips off all leading directory information --> <mapper type="flatten"/> </copy> <echo message="*****初始化,下载maven库结束****"/> </target> <path id="class1"> <fileset dir="${testng.dir}" includes="*jar"/> <pathelement location="${dest}"/> <pathelement location="${src}"/> </path> <taskdef resource="testngtasks" classpath="${testng.dir}/testng-7.0.0-beta1.jar"/> <target name="init"> <echo message="*****删除编辑文件目录****"/> <delete dir="${dest}"/> <echo message="*****创建编辑文件目录****"/> <mkdir dir="${dest}"/> </target> <target name="compile" depends="downJar"> <javac srcdir="${src}" destdir="${dest}" classpathref="class1" encoding="UTF8" includeantruntime="off" debug="on" debuglevel="lines,vars,source"/> </target> <target name="regression" depends="compile"> <echo>running testng</echo> <testng outputdir="${testng.output.dir}" classpathref="class1" delegateCommandSystemProperties="true"> <xmlfileset dir="${basedir}" includes="testng.xml"/> </testng> </target> </project>
3.运行build.xml
可以右键Run As——Ant build
也可以用cmd进入build.xml所在目录,使用ant命令