1、忽略测试
忽略测试就是@Test(enabled = false),false不执行,true执行
package com.lsc;
import org.testng.annotations.Test;
public class threeIgnoreTest {
@Test
public void ignore1(){
System.out.println("ignore 1 执行");
}
@Test(enabled = false)
public void ignore2(){
System.out.println("ignore");
}
@Test(enabled = true)
public void ignore3(){
System.out.println("ignore 3 执行");
}
}
执行结果(执行ignore1、ignore3):
执行结果(执行ignore1):
2、组测试
组测试:通过groups标签通过BeforeGroups和AfterGroups在用例前后添加步骤
package com.lsc;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class threeGroupsTest {
@Test(groups = "server")
public void test1(){
System.out.println("这是server 1 测试.......");
}
@Test(groups = "server")
public void test2(){
System.out.println("这是server 2测试.............");
}
@Test
public void test3(){
System.out.println("这是客户端 1测试...........");
}
@BeforeGroups("server")
public void Server1(){
System.out.println("这是server测试之前执行的------------");
}
@AfterGroups("server")
public void Server2(){
System.out.println("这是server测试执行之后执行的***********");
}
}
执行结果(groups=server用例前后添加执行步骤):
package com.lsc;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class threeGroupsTest {
@Test(groups = "server")
public void test1(){
System.out.println("这是server 1 测试.......");
}
@Test(groups = "server")
public void test2(){
System.out.println("这是server 2测试.............");
}
@Test(groups="client")
public void test3(){
System.out.println("这是客户端 1测试...........");
}
@BeforeGroups("client")
public void Server1(){
System.out.println("这是server测试之前执行的------------");
}
@AfterGroups("client")
public void Server2(){
System.out.println("这是server测试执行之后执行的***********");
}
}
执行结果(groups=client用例前后添加执行步骤):