TestNG忽略测试
有时,我们的代码是没有准备好,如果测试用例写入到测试方法/代码将无法运行,在这种情况下,@Test(enabled = false)有助于禁用此测试用例执行
使用例子
public class TestEnable {
@Test
public void testcase1(){
System.out.println("testcase1");
}
@Test(enabled = false)
public void testcase2(){
System.out.println("testcase2");
}
@Test
public void testcase3(){
System.out.println("testcase3");
}
}
运行结果
[TestNG] Running:
C:\Users\Administrator\.IntelliJIdea2016.3\system\temp-testng-customsuite.xml
testcase1
testcase3
从上面可以看到testcase2已经被忽略掉了
TestNG超时测试
当一个测试用例里面有某些部分会导致耗时异常,比如里面有个循环,导致死循环,那么我们不可能一直在这个测试用例等待这个用例运行,我们可以设定预定的用例执行最大时间,超出这个时间,这个用例就认为失败,接着运行下面的测试用例。
达到这个目的,我们可以使用@Test(timeout=)来实现
使用例子
public class TestTimeOut {
@Test(timeOut = 1000)
public void testcase1(){
try {
Thread.sleep(999);
System.out.println("testcase1");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Test(timeOut = 1000)
public void