use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedTestTemplateMethods.
@Test
@DisplayName("is applied on annotated @TestTemplate methods")
void appliesTimeoutOnAnnotatedTestTemplateMethods() {
EngineExecutionResults results = executeTests(//
request().selectors(//
selectMethod(TimeoutAnnotatedTestMethodTestCase.class, "testTemplateMethod")).configurationParameter(DEFAULT_TEST_TEMPLATE_METHOD_TIMEOUT_PROPERTY_NAME, //
"42ns").build());
Stream.of("repetition 1", "repetition 2").forEach(displayName -> {
Execution execution = findExecution(results.testEvents(), displayName);
//
assertThat(execution.getDuration()).isGreaterThanOrEqualTo(//
Duration.ofMillis(10)).isLessThan(Duration.ofSeconds(1));
//
assertThat(execution.getTerminationInfo().getExecutionResult().getThrowable().orElseThrow()).isInstanceOf(//
TimeoutException.class).hasMessage("testTemplateMethod() timed out after 10 milliseconds");
});
}
use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.
the class TimeoutExtensionTests method appliesTimeoutOnAnnotatedAfterEachMethods.
@Test
@DisplayName("is applied on annotated @AfterEach methods")
void appliesTimeoutOnAnnotatedAfterEachMethods() {
EngineExecutionResults results = executeTests(//
request().selectors(//
selectClass(TimeoutAnnotatedAfterEachMethodTestCase.class)).configurationParameter(DEFAULT_AFTER_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("tearDown() timed out after 10 milliseconds");
}
use of org.junit.platform.testkit.engine.EngineExecutionResults 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.EngineExecutionResults 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.EngineExecutionResults in project junit5 by junit-team.
the class IgnoreConditionTests method ignoredAndNotIgnoredTestMethods.
@Test
void ignoredAndNotIgnoredTestMethods() {
EngineExecutionResults executionResults = executeTestsForClass(IgnoredMethodsTestCase.class);
Events containers = executionResults.containerEvents();
Events tests = executionResults.testEvents();
// executionResults.allEvents().debug();
// executionResults.allEvents().debug(System.err);
// containers.debug();
// tests.debug(System.err);
// tests.debug();
// tests.skipped().debug();
// tests.started().debug();
// tests.succeeded().debug();
// executionResults.allEvents().executions().debug();
// containers.executions().debug();
// tests.executions().debug();
executionResults.allEvents().executions().assertThatExecutions().hasSize(5);
containers.executions().assertThatExecutions().hasSize(2);
tests.executions().assertThatExecutions().hasSize(3);
// @formatter:off
// tests.debug().assertEventsMatchExactly(
tests.assertEventsMatchExactly(event(test("ignoredWithCustomMessage"), skippedWithReason("Ignored Method")), event(test("notIgnored"), started()), event(test("notIgnored"), finishedSuccessfully()), event(test("ignoredWithDefaultMessage"), skippedWithReason(reason -> reason.endsWith("ignoredWithDefaultMessage() is disabled via @org.junit.Ignore"))));
// @formatter:on
}
Aggregations