工程目录结构
4Fci~qgBVi-A7u0
.src
.test-output
.testng.xml
51Testing软件测试网^X/S0b;_9b \
1.src目录执行
Dd1w(}j7T0
java org.testng.TestNG D:\Users\Administrator\workspace\testng_sample\testng.xml
也可以使用相对目录
java org.testng.TestNG ..\testng.xml
51Testing软件测试网xM Z?Wp)J
2.testng.xml所在目录执行
java -classpath "%classpath%;D:\Users\Administrator\workspace\testng_sample\src" org.testng.TestNG testng.xml
51Testing软件测试网5ZO)]1rz:Q
3.再次执行失败步骤
执行失败后,testoutput文件夹会生成testng-failed.xml这个文件,可以再次执行
51Testing软件测试网)BhU*v3E`3V
D:\Users\Administrator\workspace\testng_sample>java -classpath "%classpath%;D:\Users\Administrator\workspace\testng_sample\src" org.testng.TestNG test-output\testng-failed.xml
确保testng.jar已经被加入到classpath环境变量中
2[:w'N,PU)JuO0
4.执行jar包
将需要执行的所有java类文件和testng.xm一起导出为jar包
java org.testng.TestNG -testjar autotest.jar(testng.xml包含在jar包中的根目录)
或
java org.testng.TestNG -testjar autotest.jar testng.xml(testng.xml不在jar包中)
4\0{rC.W:R}f0
或
java org.testng.TestNG -xmlpathinjar resources/testng.xml autotest.jar
resources/testng.xml为testng.xml在jar包中的位置
51Testing软件测试网0]&und$g {/LDi
x
5.指定报告文件夹
java org.testng.TestNG -d report testng.xml
k8BS@s~u(H0
6.-listener:指定jianting类
java org.testng.TestNG -listener myListener testng1.xml
9Z7Ce_O4v0
,vz9~`PX0
7.指定要执行的groups以及所需的class
java org.testng.TestNG -groups group1 -testclass test1.NewTest
%D7k5Q^,S*U%y(h5c0
51Testing软件测试网U q#G@R6}(k
jianting类的实现
public class myListener extends TestListenerAdapter {
51Testing软件测试网:Z/@W-Oz+e}7~
@Override
public void onTestFailure(ITestResult tr) {
super.onTestFailure(tr);
……