Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 851 Bytes

File metadata and controls

42 lines (33 loc) · 851 Bytes

1.5 超时测试

若测试用例比指定毫秒数话费了更多的时间,则JUnit将会记为失败。

@Test(timeout=xx ms)

示例

public class TimeoutTest {
    @Test(timeout = 2000)
    public void test1() throws InterruptedException {
        System.out.println("test1 start");
        Thread.sleep(1000);
        System.out.println("test1 end");
    }

    @Test(timeout = 1000)
    public void test2() throws InterruptedException {
        System.out.println("test2 start");
        Thread.sleep(1000);
        System.out.println("test2 end");
    }

    @Test(timeout = 500)
    public void test3() throws InterruptedException {
        System.out.println("test3 start");
        Thread.sleep(1000);
        System.out.println("test3 end");
    }
}
test1 start
test1 end
test2 start
test2 end
test3 start