Search in sources :

Example 21 with ExecutionEventRecorder

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

the class TestInstancePostProcessorTests method instancePostProcessorsInNestedClasses.

@Test
void instancePostProcessorsInNestedClasses() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(OuterTestCase.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    // @formatter:off
    assertThat(callSequence).containsExactly(// OuterTestCase
    "fooPostProcessTestInstance:OuterTestCase", "beforeOuterMethod", "testOuter", "fooPostProcessTestInstance:OuterTestCase", "fooPostProcessTestInstance:InnerTestCase", "barPostProcessTestInstance:InnerTestCase", "beforeOuterMethod", "beforeInnerMethod", "testInner");
// @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 22 with ExecutionEventRecorder

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

the class TestInstancePostProcessorTests method testSpecificTestInstancePostProcessorIsCalled.

@Test
void testSpecificTestInstancePostProcessorIsCalled() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(TestCaseWithTestSpecificTestInstancePostProcessor.class)).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertThat(callSequence).containsExactly("fooPostProcessTestInstance:TestCaseWithTestSpecificTestInstancePostProcessor", "beforeEachMethod", "test");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 23 with ExecutionEventRecorder

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

the class ExpectedExceptionSupportTests method expectedExceptionIsProcessedCorrectly.

@Test
void expectedExceptionIsProcessedCorrectly() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(ExpectedExceptionTestCase.class);
    assertEquals(4, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(3, eventRecorder.getTestFailedCount(), "# tests failed");
    assertThat(eventRecorder.getSuccessfulTestFinishedEvents()).have(event(test("correctExceptionExpectedThrown"), finishedSuccessfully()));
    // 
    assertThat(eventRecorder.getFailedTestFinishedEvents()).haveExactly(// 
    1, event(// 
    test("noExceptionExpectedButThrown"), // 
    finishedWithFailure(message("no exception expected")))).haveExactly(// 
    1, event(// 
    test("exceptionExpectedButNotThrown"), finishedWithFailure(allOf(// 
    isA(AssertionError.class), // 
    message("Expected test to throw an instance of java.lang.RuntimeException"))))).haveExactly(// 
    1, event(// 
    test("wrongExceptionExpected"), finishedWithFailure(allOf(// 
    isA(AssertionError.class), message(value -> value.contains("Expected: an instance of java.io.IOException"))))));
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 24 with ExecutionEventRecorder

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

the class ExpectedExceptionSupportTests method expectedExceptionSupportWithoutExpectedExceptionRule.

@Test
void expectedExceptionSupportWithoutExpectedExceptionRule() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(ExpectedExceptionSupportWithoutExpectedExceptionRuleTestCase.class);
    assertEquals(2, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestAbortedCount(), "# tests aborted");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    assertThat(eventRecorder.getSuccessfulTestFinishedEvents()).have(event(test("success"), finishedSuccessfully()));
    // 
    assertThat(eventRecorder.getFailedTestFinishedEvents()).haveExactly(1, event(// 
    test("failure"), finishedWithFailure(message("must fail"))));
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 25 with ExecutionEventRecorder

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

the class LauncherBasedEnableRuleMigrationSupportTests method executeTests.

private ExecutionEventRecorder executeTests(LauncherDiscoveryRequest request) {
    TestDescriptor testDescriptor = discoverTests(request);
    ExecutionEventRecorder eventRecorder = new ExecutionEventRecorder();
    engine.execute(new ExecutionRequest(testDescriptor, eventRecorder, request.getConfigurationParameters()));
    return eventRecorder;
}
Also used : ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor)

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