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

}

}