Search in sources :

Example 96 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method beforeEachMethodThrowsAnException.

@Test
void beforeEachMethodThrowsAnException() {
    EngineExecutionResults executionResults = executeTestsForClass(ExceptionInBeforeEachMethodTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(0, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(0, executionResults.testEvents().skipped().count(), "# tests skipped");
    assertEquals(0, executionResults.testEvents().aborted().count(), "# tests aborted");
    assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed");
    // @formatter:off
    assertEquals(asList(// throws an exception.
    "beforeEachMethod", // fooAfterTestExecutionCallback should not get invoked.
    "afterEachMethod"), callSequence, "wrong call sequence");
    // @formatter:on
    assertNull(actualExceptionInAfterTestExecution, "test exception (fooAfterTestExecutionCallback should not have been called)");
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 97 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method beforeTestExecutionCallbackThrowsAnException.

@Test
void beforeTestExecutionCallbackThrowsAnException() {
    EngineExecutionResults executionResults = executeTestsForClass(ExceptionInBeforeTestExecutionCallbackTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(0, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(0, executionResults.testEvents().skipped().count(), "# tests skipped");
    assertEquals(0, executionResults.testEvents().aborted().count(), "# tests aborted");
    assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed");
    // @formatter:off
    assertEquals(asList("beforeEachMethod", "fooBeforeTestExecutionCallback", // throws an exception.
    "exceptionThrowingBeforeTestExecutionCallback", // test() should not get invoked.
    "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback", "afterEachMethod"), callSequence, "wrong call sequence");
    // @formatter:on
    assertNotNull(actualExceptionInAfterTestExecution, "test exception");
    assertTrue(actualExceptionInAfterTestExecution.isPresent(), "test exception should be present");
    assertEquals(EnigmaException.class, actualExceptionInAfterTestExecution.get().getClass());
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 98 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method afterTestExecutionCallbackThrowsAnException.

@Test
void afterTestExecutionCallbackThrowsAnException() {
    EngineExecutionResults executionResults = executeTestsForClass(ExceptionInAfterTestExecutionCallbackTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(0, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(0, executionResults.testEvents().skipped().count(), "# tests skipped");
    assertEquals(0, executionResults.testEvents().aborted().count(), "# tests aborted");
    assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed");
    // @formatter:off
    assertEquals(asList("beforeEachMethod", "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", "test", "barAfterTestExecutionCallback", // throws an exception.
    "exceptionThrowingAfterTestExecutionCallback", "fooAfterTestExecutionCallback", "afterEachMethod"), callSequence, "wrong call sequence");
    // @formatter:on
    assertNotNull(actualExceptionInAfterTestExecution, "test exception");
    assertTrue(actualExceptionInAfterTestExecution.isPresent(), "test exception should be present");
    assertEquals(EnigmaException.class, actualExceptionInAfterTestExecution.get().getClass());
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 99 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class ExecutionConditionTests method conditionWorksOnContainer.

@Test
void conditionWorksOnContainer() {
    EngineExecutionResults executionResults = executeTestsForClass(TestCaseWithExecutionConditionOnClass.class);
    executionResults.containerEvents().assertStatistics(stats -> stats.skipped(1));
    executionResults.testEvents().assertStatistics(stats -> stats.started(0));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) Test(org.junit.jupiter.api.Test)

Example 100 with EngineExecutionResults

use of org.junit.platform.testkit.engine.EngineExecutionResults in project junit5 by junit-team.

the class ExecutionConditionTests method assertExecutionConditionOverride.

private void assertExecutionConditionOverride(String deactivatePattern, int testStartedCount, int testFailedCount) {
    // @formatter:off
    LauncherDiscoveryRequest request = request().selectors(selectClass(TestCaseWithExecutionConditionOnClass.class)).configurationParameter(DEACTIVATE_CONDITIONS_PATTERN_PROPERTY_NAME, deactivatePattern).build();
    // @formatter:on
    EngineExecutionResults executionResults = executeTests(request);
    Events containers = executionResults.containerEvents();
    Events tests = executionResults.testEvents();
    containers.assertStatistics(stats -> stats.skipped(0).started(2));
    tests.assertStatistics(stats -> stats.started(testStartedCount).failed(testFailedCount));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Events(org.junit.platform.testkit.engine.Events)

Aggregations

EngineExecutionResults (org.junit.platform.testkit.engine.EngineExecutionResults)139 Test (org.junit.jupiter.api.Test)134 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)32 DynamicTest (org.junit.jupiter.api.DynamicTest)30 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)30 Events (org.junit.platform.testkit.engine.Events)27 DisplayName (org.junit.jupiter.api.DisplayName)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)15 IOException (java.io.IOException)12 Execution (org.junit.platform.testkit.engine.Execution)12 TimeoutException (java.util.concurrent.TimeoutException)10 List (java.util.List)8 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)8 ArrayList (java.util.ArrayList)7 AfterAll (org.junit.jupiter.api.AfterAll)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 BeforeAll (org.junit.jupiter.api.BeforeAll)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Nested (org.junit.jupiter.api.Nested)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7