Search in sources :

Example 11 with LauncherDiscoveryRequest

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

the class DiscoveryRequestCreatorTests method convertsExcludeClassNamePatternOption.

@Test
void convertsExcludeClassNamePatternOption() {
    options.setScanClasspath(true);
    options.setExcludedClassNamePatterns(asList("Foo.*Bar", "Bar.*Foo"));
    LauncherDiscoveryRequest request = convert();
    List<ClassNameFilter> filter = request.getFiltersByType(ClassNameFilter.class);
    assertThat(filter).hasSize(2);
    assertThat(filter.get(1).toString()).contains("Foo.*Bar");
    assertThat(filter.get(1).toString()).contains("Bar.*Foo");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ClassNameFilter(org.junit.platform.engine.discovery.ClassNameFilter) Test(org.junit.jupiter.api.Test)

Example 12 with LauncherDiscoveryRequest

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

the class LauncherFactoryTests method create.

@Test
void create() {
    LauncherDiscoveryRequest discoveryRequest = createLauncherDiscoveryRequestForBothStandardEngineExampleClasses();
    TestPlan testPlan = LauncherFactory.create().discover(discoveryRequest);
    Set<TestIdentifier> roots = testPlan.getRoots();
    assertThat(roots).hasSize(2);
    // @formatter:off
    List<String> ids = roots.stream().map(TestIdentifier::getUniqueId).collect(toList());
    // @formatter:on
    assertThat(ids).containsOnly("[engine:junit-vintage]", "[engine:junit-jupiter]");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 13 with LauncherDiscoveryRequest

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

the class TestExecutionExceptionHandlerTests method exceptionHandlerConvertsException.

@Test
void exceptionHandlerConvertsException() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testConvert")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertTrue(ConvertException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(ATestCase.class), started()), // 
    event(test("testConvert"), started()), // 
    event(test("testConvert"), finishedWithFailure(allOf(isA(IOException.class), message("checked")))), // 
    event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 14 with LauncherDiscoveryRequest

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

the class TestExecutionExceptionHandlerTests method exceptionHandlerRethrowsException.

@Test
void exceptionHandlerRethrowsException() {
    LauncherDiscoveryRequest request = request().selectors(selectMethod(ATestCase.class, "testRethrow")).build();
    ExecutionEventRecorder eventRecorder = executeTests(request);
    assertTrue(RethrowException.handleExceptionCalled, "TestExecutionExceptionHandler should have been called");
    assertRecordedExecutionEventsContainsExactly(// 
    eventRecorder.getExecutionEvents(), // 
    event(engine(), started()), // 
    event(container(ATestCase.class), started()), // 
    event(test("testRethrow"), started()), // 
    event(test("testRethrow"), finishedWithFailure(allOf(isA(IOException.class), message("checked")))), // 
    event(container(ATestCase.class), finishedSuccessfully()), event(engine(), finishedSuccessfully()));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 15 with LauncherDiscoveryRequest

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

the class BeforeAndAfterEachTests method beforeEachCallbackThrowsAnException.

@Test
void beforeEachCallbackThrowsAnException() {
    LauncherDiscoveryRequest request = request().selectors(selectClass(ExceptionInBeforeEachCallbackTestCase.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", // throws an exception.
    "exceptionThrowingBeforeEachCallback", // afterEachMethod should not get invoked.
    "barAfterEachCallback", "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