JUnit4 入门笔记

时间:2022-04-01 22:56:57

Test注解的两个可选参数 expected timeout

The Test annotation supports two optional parameters.

  The first, expected, declares that a test method should throw an exception.

  If it doesn't throw an exception or if it throws a different exception than the one declared, the test fails.

@Test(expected = Exception.class)
public void Test() {
}

The second optional parameter, timeout, causes a test to fail if it takes longer than a specified amount of clock time (measured in milliseconds).

@Test(timeout = 1000)
public void Test() {
}