如果想把timeout太久的测试自动标记为失败,有两种方法:

1.在 @Test里加上 Timeout 参数

定义"timeout=1000“的话,如果超过1000 毫秒,failure会被一个抛出的异常触发。

import static org.junit.Assert.*;
import org.junit.Test; public class TimeoutTest { @Test(timeout=1000)
public void test(){
assertTrue("it should be true",true);
}
}

2.定义Timeout 规则(应用于整个测试类)

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout; public class Timeout2 {
public static String log; @Rule
public Timeout globalTimeout=new Timeout(10000); @Test
public void test01(){
log +="ran1";
for(;;){}
} @Test
public void test02(){
log+="ran2";
for(;;){}
}
}

Timeout for tests的更多相关文章

  1. Rules

    我们之前处理异常的时候用到过Rules,当然还有很多其他规则.Rules允许弹性的添加或者重定义测试方法的行为.测试者可以重复使用或者扩展下面的某一个Rules,也可以写一个属于自己的规则. 这里先展 ...

  2. JUnit4单元测试基础篇

    引言 JUnit作为Java语言的测试框架,在测试驱动开发(TDD)下扮演重要的角色.众所周知,无论开发大型项目还是一般的小型项目, 单元测试都至关重要.单元测试为软件可发测试维护提供了很大的便利.J ...

  3. Nodejs开源项目里怎么样写测试、CI和代码测试覆盖率

    测试 目前主流的就bdd和tdd,自己查一下差异 推荐 mocha和tape 另外Jasmine也挺有名,angularjs用它,不过挺麻烦的,还有一个选择是qunit,最初是为jquery测试写的, ...

  4. JAVA自动化之Junit单元测试框架详解

    一.JUnit概述&配置 1.Junit是什么? Junit是一个Java 编程语言的开源测试框架,用于编写和运行测试.官网 地址:https://junit.org/junit4/ 2.Ma ...

  5. 【转】CTS tests 4.2_r4

    原文网址:http://www.xuebuyuan.com/1722006.html Precondition: 1.Get android sdk 2.Set adb to environment ...

  6. angular : $eval & $timeout

    $digest: function() { var watch, value, last, watchers, length, dirty, ttl = TTL, next, current, tar ...

  7. Selenium 15: How to Run Parallel Tests Using Selenium Grid and JUnit

    In this post, I will give two techniques and describe how to run your selenium tests in parallel by ...

  8. Timeout watchdog using a standby thread

    http://codereview.stackexchange.com/questions/84697/timeout-watchdog-using-a-standby-thread he simpl ...

  9. iOS Automated Tests with UIAutomation

    参照:http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#1 UI Automation JavaScri ...

随机推荐

  1. C#-日期格式表

    自定义格式表: 格式模式      说明 d                   月中的某一天.一位数的日期没有前导零. dd                 月中的某一天.一位数的日期有一个前导零. ...

  2. VSS Admin 清除密码

    [参阅链接]http://www.cnblogs.com/Zealot/archive/2004/09/18/44309.html the secret is to hack the um.dat f ...

  3. 极端气候频现 五款开发天气预报应用的API

    http://www.csdn.net/article/2014-02-07/2818322-weather-forecast-api-for-developing-apps

  4. asp.net mvc 部署在IIS7.5上出现的[没有相关的源行]错误的解决办法

    今天在IIS7.5上部署一个MVC小项目的时候出现以下错误:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET File ...

  5. How to handle the DbEntityValidationException in C#

    When I want to use db.SaveChanges(), if some of the columns got validation error and throw DbEntityV ...

  6. 第六篇、WebSphere8.5 (商业级服务器)大规模集群

    一.前言 上一篇中讲述了WebSphere的安装与应用,该版本的WAS一般都用于开发测试(有些小应用生产环境下也会用到),在生产中绝大部份使用的WebSphere Application Server ...

  7. C# 线程间互相通信

    C#线程间互相通信主要用到两个类:AutoResetEvent和ManualResetEvent. 一.AutoResetEvent AutoResetEvent 允许线程通过发信号互相通信,线程通过 ...

  8. Bootstrap_Javascript_选项卡

    选项卡Tabs是Web中一种非常常用的功能.用户点击或悬浮对应的菜单项,能切换出对应的内容. 一 . 结构分析 Bootstrap框架中的选项卡主要有两部分内容组成: 选项卡组件(也就是菜单组件),对 ...

  9. phpexcel 一些基本的设置 (表格的基本属性)

    网址是:http://www.thinkphp.cn/code/1893.html

  10. C语言结构体(struct)使用方法

    基本定义:结构体,通俗讲就像是打包封装,把一些变量有共同特征(比如同属于某一类事物的属性)的变量封装在内部,通过一定方法访问修改内部变量. 结构体定义: 第一种:只有结构体定义 struct stuf ...