这篇先来介绍@Test注释下的一个属性-timeOut。字面意思就是超时判断,详细点说。

如果哪个测试方法需要监听执行的时间,那么就可以考虑采用timeOut属性。

例如,实际的接口测试中,加入登录接口时间不能超过3秒中。

下面来看看如何监控这个方法如果运行时间超过3秒就抛出异常。

package com.java.learn;
 
import org.testng.annotations.Test;
 
/**
 * create by Anthony on 2017/10/31
 */
public class TimeoutTest {
 
    @Test(timeOut = 3000)
    public void loginTest(){
        try{
            Thread.sleep(3100);
        }catch (InterruptedException e){
            System.out.println(e.toString());
        }
 
    }
}

  

运行下这个Testng测试用例,看是否抛出异常。

TestNG入门教程-5-timeOut属性

 

 

我们来更改下Thread.sleep(2800);再次运行,看看效果。

TestNG入门教程-5-timeOut属性

 

 

总结:当某些测试用例需要测试运行时间(一般在接口测试中会遇到)的时候,利用@Test这个注释中的timeOut属性,可以帮你做到监控时间的功能。

相关文章:

  • 2021-08-01
  • 2021-11-16
  • 2021-08-04
  • 2021-08-09
  • 2021-07-22
猜你喜欢
  • 2021-05-22
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案