use of org.junit.platform.testkit.engine.Execution in project junit5 by junit-team.
the class TimeoutExtensionTests method reportsIllegalTimeoutDurations.
@Test
@DisplayName("reports illegal timeout durations")
void reportsIllegalTimeoutDurations() {
EngineExecutionResults results = executeTestsForClass(IllegalTimeoutDurationTestCase.class);
Execution execution = findExecution(results.testEvents(), "testMethod()");
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(//
PreconditionViolationException.class).hasMessage("timeout duration must be a positive number: 0");
}
use of org.junit.platform.testkit.engine.Execution in project junit5 by junit-team.
the class TimeoutExtensionTests method failsMethodsWithoutInterruptedException.
@Test
@DisplayName("fails methods that do not throw InterruptedException")
void failsMethodsWithoutInterruptedException() {
EngineExecutionResults results = executeTestsForClass(MethodWithoutInterruptedExceptionTestCase.class);
Execution execution = findExecution(results.testEvents(), "methodThatDoesNotThrowInterruptedException()");
//
assertThat(execution.getDuration()).isGreaterThanOrEqualTo(//
Duration.ofMillis(1)).isLessThan(Duration.ofSeconds(1));
assertThat(execution.getTerminationInfo().getExecutionResult().getStatus()).isEqualTo(FAILED);
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(//
TimeoutException.class).hasMessage("methodThatDoesNotThrowInterruptedException() timed out after 1 millisecond");
}
use of org.junit.platform.testkit.engine.Execution in project junit5 by junit-team.
the class TimeoutExtensionTests method applyTimeoutOnAnnotatedTestMethodsUsingDisabledOnDebugTimeoutMode.
@Test
@DisplayName("is not applied on annotated @Test methods using timeout mode: disabled")
void applyTimeoutOnAnnotatedTestMethodsUsingDisabledOnDebugTimeoutMode() {
EngineExecutionResults results = executeTests(//
request().selectors(//
selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testMethod")).configurationParameter(DEFAULT_TEST_METHOD_TIMEOUT_PROPERTY_NAME, //
"42ns").configurationParameter(TIMEOUT_MODE_PROPERTY_NAME, "disabled_on_debug").build());
Execution execution = findExecution(results.testEvents(), "testMethod()");
//
assertThat(execution.getDuration()).isGreaterThanOrEqualTo(//
Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(2));
// Should we test if we're debugging? This test will fail if we are debugging.
if (RuntimeUtils.isDebugMode()) {
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable()).isEmpty();
} else {
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(//
TimeoutException.class).hasMessage("testMethod() timed out after 10 milliseconds");
}
}
use of org.junit.platform.testkit.engine.Execution in project junit5 by junit-team.
the class TimeoutExtensionTests method includesClassNameIfMethodIsNotInTestClass.
@Test
@DisplayName("includes fully qualified class name if method is not in the test class")
void includesClassNameIfMethodIsNotInTestClass() {
EngineExecutionResults results = executeTestsForClass(NestedClassWithOuterSetupMethodTestCase.class);
Execution execution = findExecution(results.testEvents(), "testMethod()");
//
assertThat(execution.getDuration()).isGreaterThanOrEqualTo(//
Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(//
TimeoutException.class).hasMessageEndingWith("$NestedClassWithOuterSetupMethodTestCase#setUp() timed out after 10 milliseconds");
}
use of org.junit.platform.testkit.engine.Execution in project junit5 by junit-team.
the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedBeforeEachMethods.
@Test
@DisplayName("is applied on annotated @BeforeEach methods")
void appliesTimeoutOnAnnotatedBeforeEachMethods() {
EngineExecutionResults results = executeTests(//
request().selectors(//
selectClass(TimeoutAnnotatedBeforeEachMethodTestCase.class)).configurationParameter(DEFAULT_BEFORE_EACH_METHOD_TIMEOUT_PROPERTY_NAME, //
"42ns").build());
Execution execution = findExecution(results.testEvents(), "testMethod()");
//
assertThat(execution.getDuration()).isGreaterThanOrEqualTo(//
Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(//
TimeoutException.class).hasMessage("setUp() timed out after 10 milliseconds");
}
Aggregations