您的位置:首页 > 其它

Junit 小案例 测试超时

2015-10-20 17:22 260 查看
package com.laiwenhua.junitTest;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
/**
* 测试超时
* @author 绵敏
*
*/
public class TestTimeOut {
//第一种方式,使用Test的timeout属性
@Test(timeout=1000)
public void testAdd() {
System.out.println("------一秒钟超时--------");
while(true){}
}
//第二种方式,使用Timeout规则
@Rule
public Timeout globalTimeout=new Timeout(5000);
@Test
public void timeoutIn5Second() {
System.out.println("------5s超时--------");
while(true){}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息