1、TestNG按顺序执行Case
1)优先级法:@Test(Priority=?)优先级设置的值越小,则越优先。
2)字母排序法:由@Test的方法名的首字母由a~~z。
3)在xml中设置标识 preserve-order可以控制类和方法执行顺序,其顺序就是xml中指定的顺序。
<
test
name
="test12"
preserve-order
="true">
2、TestNG异常测试
@Test(expectedExceptions=ArithmeticException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
预期该方法中会出现这样的异常,一旦运行的时候出现异常则认为是测试通过,获取到了该异常不会报失败
3、TestNG测试分组
1) 在方法上的分组
package TankLearn2.Learn;
import org.testng.annotations.Test;
public class GroupTest {
@Test(groups = {"selenium-test"})
public void testLogin(){
System.out.println("this is test login");
}
@Test(groups = {"functiontest"})
public void testOpenPage(){
System.out.println("this is test Open Page");
}
}
import org.testng.annotations.Test;
public class GroupTest {
@Test(groups = {"selenium-test"})
public void testLogin(){
System.out.println("this is test login");
}
@Test(groups = {"functiontest"})
public void testOpenPage(){
System.out.println("this is test Open Page");
}
}
然后在testng.xml中 按组执行测试用例
<?
xml version="1.0" encoding="UTF-8"
?>
<!
DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"
>
<
suite
name
="Suite1">
<
test
name
="test1">
<
groups
>
<
run
>
<
include
name
="
selenium-test
"
/>
</
run
>
</
groups
>