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
  • 相关阅读:
    centos7 忘记mysql5.7密码
    阿里云Linux(Centos7)下搭建SVN服务器
    JAVA金额格式字符串转数值
    win10下RabbitMQ的安装和配置
    Oracle update 两表及以上关联更新,出现多值情况,不是一对一更新
    java.lang.OutOfMemoryError: java heap space
    bootstrap.min.css.map
    css 边距等常用设置
    html 标签
    数据库总结
  • 原文地址:https://www.cnblogs.com/linxinmeng/p/12593711.html
Copyright © 2011-2022 走看看