TestNg线程池配置、执行次数配置、超时配置

使用注解的方式对TestNg线程池配置、执行次数配置、超时配置

注:使用注解来控制测试方法运行的次数和超时时间,timeOut在单线程或者多线程模式下都可用,threadPoolSize设置了线程池的个数 * ,在观察结果时,发现很多值是重复的,但是可能不等于我们配置的线程池个数,因为线程的个数还取决于硬件CPU的支持,

invocationCount----表示执行的次数

threadPoolSize-----表示线程池的内线程的个数

timeOut-------超时时间-毫秒

代码实例:

 

public class TestngInvocationCount {  
    private static int sum = 0;  
  
    @Test(threadPoolSize = 2, invocationCount = 10, timeOut = 1000)  
    public void testServer() throws InterruptedException {  
        // 检测启动的线程数,当启动的个数超过CPU核数时,其实是重新在调度  
        // Thread.sleep(2000);  
        sum++;  
        System.out.println("........." + sum);  
    }  
  
}  

 

测试结果:

 

[TestNG] Running:
  C:\Users\Administrator\.IntelliJIdea2018.2\system\temp-testng-customsuite.xml
.........1
.........2
.........3
.........4
.........5
.........6
.........7
.........8
.........9
.........10

===============================================
Default Suite
Total tests run: 10, Failures: 0, Skips: 0
===============================================

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

Process finished with exit code 0

 

 
 

 

转载于:https://www.cnblogs.com/longronglang/p/6123778.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值