Junit 小案例 测试超时

package com.laiwenhua.junitTest;ide



import org.junit.BeforeClass;测试

import org.junit.Rule;spa

import org.junit.Test;it

import org.junit.rules.Timeout;class

/**test

 * 测试超时import

 * @author 绵敏im

 *tab

 */di

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

}

}

相关文章
相关标签/搜索