TestNG,timeOut

这篇先来介绍@Test注释下的一个属性-timeOut。字面意思就是超时判断,详细点说。如果哪个测试方法需要监听执行的时间,那么就可以考虑采用timeOut属性。例如,实际的接口测试中,加入登录接口时间不能超过3秒中。下面来看看如何监控这个方法如果运行时间超过3秒就抛出异常。

 1 package com.java.learn;
 2  
 3 import org.testng.annotations.Test;
 4  
 5 /**
 6  * create by Anthony on 2017/10/31
 7  */
 8 public class TimeoutTest {
 9  
10     @Test(timeOut = 3000)
11     public void loginTest(){
12         try{
13             Thread.sleep(3100);
14         }catch (InterruptedException e){
15             System.out.println(e.toString());
16         }
17  
18     }
19 }

 

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

 


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

 


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


---------------------
作者:Anthony_tester
来源:CSDN
原文:https://blog.csdn.net/u011541946/article/details/78472642
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-01-02 15:49  HkGov  阅读(532)  评论(0编辑  收藏  举报