一、TestNG按顺序执行case
在testng.xml中,可以控制测试用例按顺序执行。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test" preserve-order="true">
<classes>
<class name="com.test.testNG.SampleTest"/>
<methods>
<include name="oneMethod"/>
<include name="threeMethod"/>
<include name="twoMethod"/>
</methods>
</classes>
</test>
</suite>
二、TestNG分组执行
为方法分别指定分组,代码如下
package com.test.testNG;
import org.testng.annotations.*;
public class SampleTest {
@Test (groups = {"groupOne"})//指定分组
public void testMethod1(){
System.out.println("*111111111111111111111");
}
@Test (groups = {"groupTwo"})
public void testMethod2(){
System.out.println("*2222222222222222222222");
}
@Test (groups = {"groupOne"})
public void testMethod3(){
System.out.println("*11111111111111111*");
}
}
xml文件配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name = "groupOne"/> <!-- 指定要运行的组 -->
</run>
</groups>
<classes>
<class name="com.test.testNG.SampleTest"/> <!-- 指定要运行的类 -->
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
三、TestNG忽略测试
package com.test.testNG;
import org.testng.annotations.*;
public class SampleTest {
@Test (enable=false)
public void testMethod2(){
System.out.println("方法被忽略啦啦啦啦");
}
五、TestNG依赖测试
package com.test.testNG;
import org.testng.annotations.*;
public class SampleTest {
@Test(dependsOnMethods={"setp1"})
public void setp2(){
System.out.println("222222222222222");
}
@Test
public void setp1(){
System.out.println("111111111111111");
}
}
执行结果: