Search in sources :

Example 16 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class BeforeAndAfterEachTests method beforeEachAndAfterEachCallbacks.

@Test
void beforeEachAndAfterEachCallbacks() {
    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
    "fooBeforeEachCallback", "barBeforeEachCallback", "beforeEachMethod", "testOuter", "afterEachMethod", "barAfterEachCallback", "fooAfterEachCallback", // InnerTestCase
    "fooBeforeEachCallback", "barBeforeEachCallback", "fizzBeforeEachCallback", "beforeEachMethod", "beforeEachInnerMethod", "testInner", "afterEachInnerMethod", "afterEachMethod", "fizzAfterEachCallback", "barAfterEachCallback", "fooAfterEachCallback"), 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 17 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class BeforeAndAfterEachTests method beforeEachMethodThrowsAnException.

@Test
void beforeEachMethodThrowsAnException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(ExceptionInBeforeEachMethodTestCase.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");
    // Since the JVM does not guarantee the order in which methods are
    // returned via reflection (and since JUnit Jupiter does not yet
    // support ordering of @BeforeEach methods), we have to figure out
    // which @BeforeEach method got executed first in order to determine
    // the expected call sequence.
    // @formatter:off
    List<String> list1 = asList("fooBeforeEachCallback", // throws an exception.
    "beforeEachMethod1", // test should not get invoked.
    "afterEachMethod", "fooAfterEachCallback");
    List<String> list2 = asList("fooBeforeEachCallback", "beforeEachMethod2", // throws an exception.
    "beforeEachMethod1", // test should not get invoked.
    "afterEachMethod", "fooAfterEachCallback");
    // @formatter:on
    List<String> expected = beforeEachMethodCallSequence.get(0).equals("beforeEachMethod1") ? list1 : list2;
    assertEquals(expected, callSequence, "wrong call sequence");
    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 18 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class BeforeAndAfterEachTests method beforeEachAndAfterEachCallbacksDeclaredOnSuperclassAndSubclass.

@Test
void beforeEachAndAfterEachCallbacksDeclaredOnSuperclassAndSubclass() {
    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("fooBeforeEachCallback", "barBeforeEachCallback", "testChild", "barAfterEachCallback", "fooAfterEachCallback"), 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 LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.

the class BeforeAndAfterEachTests method afterEachCallbackThrowsAnException.

@Test
void afterEachCallbackThrowsAnException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(ExceptionInAfterEachCallbackTestCase.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", "barBeforeEachCallback", "beforeEachMethod", "test", "afterEachMethod", "barAfterEachCallback", // throws an exception.
    "exceptionThrowingAfterEachCallback", "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 20 with LauncherDiscoveryRequest

use of org.junit.platform.launcher.LauncherDiscoveryRequest 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)

Aggregations

LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)167 Test (org.junit.jupiter.api.Test)141 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)74 TestDescriptor (org.junit.platform.engine.TestDescriptor)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)33 Launcher (org.junit.platform.launcher.Launcher)16 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)11 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)11 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)11 Method (java.lang.reflect.Method)10 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 IOException (java.io.IOException)7 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)7 ArrayList (java.util.ArrayList)6 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)6 TestIdentifier (org.junit.platform.launcher.TestIdentifier)5 TestPlan (org.junit.platform.launcher.TestPlan)5 Path (java.nio.file.Path)4 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)4