(十一)TestNG 其他使用技巧

除了前面介绍的功能外,TestNG 还有一些使用技巧,相对比较简单,这里通过一个例子来演示。

其它使用技巧


import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;


public class OtherTest { // 该条用例跳过执行 @Test(enabled = false) publicvoidtestCase1(){ assertEquals(2+2, 4); } // 设定用例超时时间 @Test(timeOut = 3000) publicvoidtestCase2()throws InterruptedException { Thread.sleep(3001); } // 预设用例抛出的异常类型 @Test(expectedExceptions = RuntimeException.class) publicvoidtestCase3(){ assertEquals(2/0,1); } } 
  • enabled 设置用例是否跳过执行,默认为:true ,表示不跳过。false 表示跳过执行。

  • timeOut 设置用例运行的超时间,3000 单位为毫秒,当用例运行时间超过 3000 毫秒则判定为失败。不管用例本身是否运行失败。

  • expectedExceptions 用来预设用例运行会出现的异常。例如 2/0 将会抛出 RuntimeException 类型的异常,如果出现异常则表示用例执行成功。

猜你喜欢

转载自www.cnblogs.com/xinlan06/p/11498789.html