Junit 小案例 测试超时

Junit 小案例  测试超时

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){}

}

}