invocationCount和invocationTimeOut

这篇我们来学习下@Test中另外两个属性invocationCount和invocationTimeOut,前面我介绍了timOut这个属性,知道是超时监控的功能。同样,本篇两个属性和这个差不多,只不过是监控运行多次同一个用例的总耗时是否达到设置的最大值。

1.invocationCount

       字面意思就是调用的次数统计,这个属性是的英文解释是:The number of times this method should be invoked. 哦,原来就是这个测试用例被调用执行的次数。说明这个属性可以设置一个用例可以重复跑多次,这样理解就好。

2. invocationTimeOut

        字面意思是调用的超时,看看英文的解释:The maximum number of milliseconds this test should take for thecumulated time of all the invocationcounts. This attribute will be ignored ifinvocationCount is not specified.这句话,说了两个意思,第一个是设置一个最大的毫秒数来计算执行多次后总共耗时多少,耗时值不能超过设置的最大毫秒数。第二个意思是说,这个属性是和invocationCount结合使用才会工作。

了解了两个属性的基本含义,我们就看看代码举例。

package com.java.learn;
 
import org.testng.annotations.Test;
 
/**
 * create by Anthony on 2017/10/31
 */
public class TimeoutTest {
 
    @Test(invocationCount = 5, invocationTimeOut = 5100)
    public void loginTest() throws InterruptedException{
 
        Thread.sleep(1000);
        System.out.println("login test");
 
    }
}


代码作用:设置了执行次数数5次,5次执行总共耗时不能超过5100毫秒,否则抛出中断异常。

看看运行结果:

 

 

       这两个参数有什么作用呢?在接口测试中,或者性能测试。我们需要测试某一个功能的稳定性。例如,一个支付接口,调用一次,能够在1秒完成。那么如果调用100次,1万次,甚至更多次数。我想,大家都知道,随着服务器压力增加,不可能每次接口执行都是1秒。例如,我测试支付接口10次,总响应时间不能超过13秒。如果测试超过13秒,说明这个接口性能角度,或者压力测试角度,稳定性角度是有缺陷的,需要开发去想办法优化。


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

posted @ 2019-01-14 15:06  HkGov  阅读(581)  评论(0编辑  收藏  举报