Search in sources :

Example 16 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class BeforeAndAfterEachTests method afterEachMethodThrowsAnException.

@Test
void afterEachMethodThrowsAnException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(ExceptionInAfterEachMethodTestCase.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(0, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    assertEquals(asList("fooBeforeEachCallback", "beforeEachMethod", "test", // throws an exception.
    "afterEachMethod", "fooAfterEachCallback"), callSequence, "wrong call sequence");
    // @formatter:on
    assertThat(actualExceptionInAfterEachCallback).containsInstanceOf(EnigmaException.class);
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 17 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method beforeAndAfterTestExecutionCallbacksDeclaredOnSuperclassAndSubclass.

@Test
void beforeAndAfterTestExecutionCallbacksDeclaredOnSuperclassAndSubclass() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(ChildTestCase.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    assertEquals(asList("fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", "testChild", "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback"), callSequence, "wrong call sequence");
// @formatter:on
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 18 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method beforeAndAfterTestExecutionCallbacksDeclaredOnInterfaceAndClass.

@Test
void beforeAndAfterTestExecutionCallbacksDeclaredOnInterfaceAndClass() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(TestInterfaceTestCase.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    assertEquals(asList(// Test Interface
    "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", "defaultTestMethod", "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback", // Test Class
    "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", "localTestMethod", "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback"), callSequence, "wrong call sequence");
// @formatter:on
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 19 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method testMethodThrowsAnException.

@Test
void testMethodThrowsAnException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(ExceptionInTestMethodTestCase.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(0, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    assertEquals(asList("beforeEachMethod", "fooBeforeTestExecutionCallback", // throws an exception.
    "test", "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 : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 20 with ExecutionEventRecorder

use of org.junit.platform.engine.test.event.ExecutionEventRecorder in project junit5 by junit-team.

the class BeforeAndAfterTestExecutionCallbackTests method beforeAndAfterTestExecutionCallbacks.

@Test
void beforeAndAfterTestExecutionCallbacks() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(OuterTestCase.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestSkippedCount(), "# tests skipped");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    assertEquals(asList(// OuterTestCase
    "beforeEachMethodOuter", "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", "testOuter", "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback", "afterEachMethodOuter", // InnerTestCase
    "beforeEachMethodOuter", "beforeEachMethodInner", "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", "fizzBeforeTestExecutionCallback", "testInner", "fizzAfterTestExecutionCallback", "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback", "afterEachMethodInner", "afterEachMethodOuter"), callSequence, "wrong call sequence");
// @formatter:on
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)114 Test (org.junit.jupiter.api.Test)104 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)74 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)12 Method (java.lang.reflect.Method)10 TestDescriptor (org.junit.platform.engine.TestDescriptor)8 IOException (java.io.IOException)6 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 TestInfo (org.junit.jupiter.api.TestInfo)4 UniqueId (org.junit.platform.engine.UniqueId)4 JupiterTestEngine (org.junit.jupiter.engine.JupiterTestEngine)3 LauncherDiscoveryRequestBuilder.request (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request)3 Map (java.util.Map)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 Assertions.allOf (org.assertj.core.api.Assertions.allOf)2