Test runner如何为Selenium中的执行对测试类进行优先级排序?
我们可以在执行期间在 TestNG 中对测试进行优先级排序。需要注意的是,只能对带有 @Test 注解的测试方法设置优先级。为测试方法设置的优先级数字越低,在执行期间其优先级越高。
只能将整数(正数、零或负数)设置为优先级。也可以将十进制数设置为优先级,但是需要通过类型转换将其转换为整数。
一个测试方法不能有多个优先级号。此外,无法从 TestNG XML 文件设置测试方法的优先级。
语法
public class TestNG {
@Test (priority = 2)
public void tC1() {
System.out.println("Test Case 1");
}示例
import org.testng.annotations.Test;
public class TestNGP {
@Test (priority = 2)
public void testCase1() {
System.out.println("This is the A Normal Test Case 1");
}
@Test (priority = 1)
public void testCase2() {
System.out.println("This is the A Normal Test Case 2");
}
@Test (priority = 3)
public void testCase3() {
System.out.println("This is the A Normal Test Case 3");
}
}输出

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP