Details

Recommendation type: Timeout

Configurable: Yes

Filter category: Exceptions / Assertion Failures

Description

UTA displays this recommendation when the time limit for executing a set of tests is exceeded.

Configuration

You can specify the timeout value when creating tests with the Add test case(s) option (it cannot be configured on the Preferences page); see Creating Multiple Unit Tests.

Example

@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