zoukankan      html  css  js  c++  java
  • testNG超时测试

    超时测试是指如果测试未超时则通过,反之则自动停止并置为运行失败;

    testNG超时设置的时间是通过 测试脚本方法上添加@Test()timeOut参数控制的,如果@Test(timeOut = 3000),3000为毫秒数,1000毫秒=1秒。

    java代码如下

     1 package com.course.testng;
     2 
     3 import org.testng.annotations.Test;
     4 
     5 public class TimeOutTest {
     6     @Test(timeOut = 3000)//单位是毫秒值  1000等于1秒
     7     public void testSuccess() throws InterruptedException {
     8         Thread.sleep(2000);
     9     }
    10 
    11     @Test(timeOut = 3000)
    12     public void testFailed() throws InterruptedException {
    13         Thread.sleep(4000);
    14     }
    15 }

    运行结果如下

      C:UsersAdministrator.IntelliJIdea2019.3system	emp-testng-customsuite.xml
    
    
    
    org.testng.internal.thread.ThreadTimeoutException: Method com.course.testng.TimeOutTest.testFailed() didn't finish within the time-out 3000
    
        at java.util.concurrent.ThreadPoolExecutor.tryTerminate(ThreadPoolExecutor.java:706)
        at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1007)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1160)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    
    
    ===============================================
    Default Suite
    Total tests run: 2, Failures: 1, Skips: 0
    ===============================================
    
    
    Process finished with exit code 0
  • 相关阅读:
    BZOJ 1143 [CTSC2008]祭祀river
    BZOJ 3997 [TJOI2015]组合数学
    BZOJ 3996 [TJOI2015]线性代数
    BZOJ 4553 [Tjoi2016&Heoi2016]序列
    微信开发之密文模式 mcrypt_module_open 走不过
    JS JSON & ARRAY 遍历
    linux ftp服务器配置(Ubuntu)
    thinkphp 吐槽篇
    游戏--疯狂猜字随机混乱正确答案逻辑
    PHP 批量去除BOM头;此文转载;
  • 原文地址:https://www.cnblogs.com/linxinmeng/p/12593711.html
Copyright © 2011-2022 走看看