详细信息

建议类型:超时

是否可在首选项配置:是

过滤器分类:异常/断言错误

说明

当一组测试的执行时间超过限制时,UTA 将显示此建议。

配置

使用添加测试用例选项创建测试时,您可以指定超时时间(无法在首选项页面配置);请参阅创建测试套件

示例

@Test(timeout = 1000)
public void testFactorial() throws Throwable {
    // Given
    Example underTest = new Example();

    // When
    int n = 10;

    AtomicInteger result = new AtomicInteger();
    CountDownLatch latch = new CountDownLatch(1);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                result.set(underTest.factorial(n));
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                latch.countDown();
            }
        }
    });

    latch.await();

    // Then
    assertEquals(3628800, result.get());
}

  • No labels