TestNG入门笔记[5]:TestNG + ANT

利用ANT+TestNG能够是自动化测试自己跑起来,不需要人工干预。

1.    在项目的根目录下新建build.xml


2.  在testng.xml文件中定义要执行的case
   
   
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="myTest" verbose='1'>
<test name="test">
<classes>
<class name="com.mytest.test"/>
</classes>
</test>
</suite>


3.  编写build.xml文件
首先,我们需要定义TestNG的ANT任务如下:
   
   
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng-6.9.10.jar"/>
</classpath>
</taskdef>
根据实际需求编写build.xml, 编译 -> 运行
   
   
<?xml version="1.0" encoding="UTF-8"?>
<project name="TestNG" default="runtest" basedir=".">
 
<property name="srcdir" location="${basedir}/src" />
<property name="libdir" location="${basedir}/lib" />
<property name="testng.output.dir" location="${basedir}/test-output" />
<property name="testng.file" value="testng.xml" />
 
<path id="cp">
<fileset dir="${libdir}" includes="*jar" />
<fileset dir="${libdir}" includes="*zip" />
<pathelement location="${basedir}/bin" />
</path>
 
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng-6.9.10.jar"/>
</classpath>
</taskdef>
 
<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" classpathref="cp" includeantruntime="off" debug="on" debuglevel="lines,vars,source" />
</target>
<target name="runtest" depends="compile">
<testng outputdir="${testng.output.dir}" classpathref="cp">
<xmlfileset dir="${basedir}" includes="${testng.file}"/>
</testng>
</target>
</project>

4.  执行build.xml






  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值