Search in sources :

Example 81 with EngineExecutionResults

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

the class LifecycleMethodExecutionExceptionHandlerTests method classLevelExceptionHandlersRethrowException.

@Test
void classLevelExceptionHandlersRethrowException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(RethrowingTestCase.class)).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertEquals(1, RethrowExceptionHandler.beforeAllCalls, "Exception should handled in @BeforeAll");
    assertEquals(1, RethrowExceptionHandler.afterAllCalls, "Exception should handled in @AfterAll");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(RethrowingTestCase.class), started()), // 
    event(container(RethrowingTestCase.class), finishedWithFailure(instanceOf(RuntimeException.class))), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 82 with EngineExecutionResults

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

the class LifecycleMethodExecutionExceptionHandlerTests method exceptionHandlersSwallowException.

@Test
void exceptionHandlersSwallowException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(SwallowingTestCase.class)).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertEquals(1, SwallowExceptionHandler.beforeAllCalls, "Exception should be handled in @BeforeAll");
    assertEquals(1, SwallowExceptionHandler.beforeEachCalls, "Exception should be handled in @BeforeEach");
    assertEquals(1, SwallowExceptionHandler.afterEachCalls, "Exception should be handled in @AfterEach");
    assertEquals(1, SwallowExceptionHandler.afterAllCalls, "Exception should be handled in @AfterAll");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(SwallowingTestCase.class), started()), // 
    event(test("aTest"), started()), // 
    event(test("aTest"), finishedSuccessfully()), // 
    event(container(SwallowingTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 83 with EngineExecutionResults

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

the class LifecycleMethodExecutionExceptionHandlerTests method testLevelExceptionHandlersConvertException.

@Test
void testLevelExceptionHandlersConvertException() {
    throwExceptionBeforeAll = false;
    throwExceptionAfterAll = false;
    LauncherDiscoveryRequest request = request().selectors(selectClass(ConvertingTestCase.class)).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertEquals(1, ConvertExceptionHandler.beforeEachCalls, "Exception should be handled in @BeforeEach");
    assertEquals(1, ConvertExceptionHandler.afterEachCalls, "Exception should be handled in @AfterEach");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(ConvertingTestCase.class), started()), // 
    event(test("aTest"), started()), // 
    event(test("aTest"), finishedWithFailure(instanceOf(IOException.class))), // 
    event(container(ConvertingTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 84 with EngineExecutionResults

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

the class LifecycleMethodExecutionExceptionHandlerTests method testLevelExceptionHandlersRethrowException.

@Test
void testLevelExceptionHandlersRethrowException() {
    throwExceptionBeforeAll = false;
    throwExceptionAfterAll = false;
    LauncherDiscoveryRequest request = request().selectors(selectClass(RethrowingTestCase.class)).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertEquals(1, RethrowExceptionHandler.beforeEachCalls, "Exception should be handled in @BeforeEach");
    assertEquals(1, RethrowExceptionHandler.afterEachCalls, "Exception should be handled in @AfterEach");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(RethrowingTestCase.class), started()), // 
    event(test("aTest"), started()), // 
    event(test("aTest"), finishedWithFailure(instanceOf(RuntimeException.class))), // 
    event(container(RethrowingTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 85 with EngineExecutionResults

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

the class LifecycleMethodExecutionExceptionHandlerTests method perClassLifecycleMethodsAreHandled.

@Test
void perClassLifecycleMethodsAreHandled() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(PerClassLifecycleTestCase.class)).build();
    EngineExecutionResults executionResults = executeTests(request);
    assertEquals(2, SwallowExceptionHandler.beforeAllCalls, "Exception should be handled in @BeforeAll");
    assertEquals(1, SwallowExceptionHandler.beforeEachCalls, "Exception should be handled in @BeforeEach");
    assertEquals(1, SwallowExceptionHandler.afterEachCalls, "Exception should be handled in @AfterEach");
    assertEquals(2, SwallowExceptionHandler.afterAllCalls, "Exception should be handled in @AfterAll");
    // 
    executionResults.allEvents().assertEventsMatchExactly(// 
    event(engine(), started()), // 
    event(container(PerClassLifecycleTestCase.class), started()), // 
    event(test("aTest"), started()), // 
    event(test("aTest"), finishedSuccessfully()), // 
    event(container(PerClassLifecycleTestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Test(org.junit.jupiter.api.Test)

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