Search in sources :

Example 11 with TestPlan

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

the class RunListenerAdapterTests method notifiedEagerlyForTestSetWhenClassExecutionStarted.

@Test
void notifiedEagerlyForTestSetWhenClassExecutionStarted() throws Exception {
    EngineDescriptor engine = newEngineDescriptor();
    TestDescriptor parent = newClassDescriptor();
    engine.addChild(parent);
    TestDescriptor child = newMethodDescriptor();
    parent.addChild(child);
    TestPlan plan = TestPlan.from(Collections.singletonList(engine));
    adapter.testPlanExecutionStarted(plan);
    adapter.executionStarted(TestIdentifier.from(engine));
    adapter.executionStarted(TestIdentifier.from(parent));
    verify(listener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), MyTestClass.class.getName()));
    verifyNoMoreInteractions(listener);
    adapter.executionStarted(TestIdentifier.from(child));
    verify(listener).testStarting(new SimpleReportEntry(MyTestClass.class.getName(), MY_TEST_METHOD_NAME));
    verifyNoMoreInteractions(listener);
    adapter.executionFinished(TestIdentifier.from(child), successful());
    verify(listener).testSucceeded(new SimpleReportEntry(MyTestClass.class.getName(), MY_TEST_METHOD_NAME));
    verifyNoMoreInteractions(listener);
    adapter.executionFinished(TestIdentifier.from(parent), successful());
    verify(listener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), MyTestClass.class.getName()));
    verifyNoMoreInteractions(listener);
    adapter.executionFinished(TestIdentifier.from(engine), successful());
    verifyNoMoreInteractions(listener);
}
Also used : SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with TestPlan

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

the class RunListenerAdapterTests method stackTraceWriterDefaultsToTestClass.

@Test
void stackTraceWriterDefaultsToTestClass() throws Exception {
    TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Some Plan")));
    adapter.testPlanExecutionStarted(plan);
    TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, "Parent", null);
    adapter.executionFinished(child, TestExecutionResult.failed(new RuntimeException("message")));
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(listener).testError(entryCaptor.capture());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter().smartTrimmedStackTrace());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter().writeTraceToString());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter().writeTrimmedTraceToString());
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 13 with TestPlan

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

the class RunListenerAdapterTests method stackTraceWriterPresentWhenParentHasSource.

@Test
void stackTraceWriterPresentWhenParentHasSource() throws Exception {
    TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Some Plan")));
    adapter.testPlanExecutionStarted(plan);
    TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, "Parent", ClassSource.from(MyTestClass.class));
    adapter.executionFinished(child, TestExecutionResult.failed(new RuntimeException()));
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(listener).testError(entryCaptor.capture());
    assertNotNull(entryCaptor.getValue().getStackTraceWriter());
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 14 with TestPlan

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

the class TestPlanScannerFilter method accept.

@Override
@SuppressWarnings("rawtypes")
public boolean accept(Class testClass) {
    // @formatter:off
    LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClass(testClass)).filters(includeAndExcludeFilters).build();
    // @formatter:on
    TestPlan testPlan = launcher.discover(discoveryRequest);
    return testPlan.containsTests();
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestPlan(org.junit.platform.launcher.TestPlan)

Example 15 with TestPlan

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

the class DefaultLauncher method execute.

private void execute(Root root, ConfigurationParameters configurationParameters, TestExecutionListener... listeners) {
    TestExecutionListenerRegistry listenerRegistry = buildListenerRegistryForExecution(listeners);
    TestPlan testPlan = TestPlan.from(root.getEngineDescriptors());
    TestExecutionListener testExecutionListener = listenerRegistry.getCompositeTestExecutionListener();
    testExecutionListener.testPlanExecutionStarted(testPlan);
    ExecutionListenerAdapter engineExecutionListener = new ExecutionListenerAdapter(testPlan, testExecutionListener);
    for (TestEngine testEngine : root.getTestEngines()) {
        TestDescriptor testDescriptor = root.getTestDescriptorFor(testEngine);
        execute(testEngine, new ExecutionRequest(testDescriptor, engineExecutionListener, configurationParameters));
    }
    testExecutionListener.testPlanExecutionFinished(testPlan);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestEngine(org.junit.platform.engine.TestEngine) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Aggregations

TestPlan (org.junit.platform.launcher.TestPlan)47 Test (org.junit.jupiter.api.Test)38 TestIdentifier (org.junit.platform.launcher.TestIdentifier)24 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)16 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)16 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)10 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)9 UniqueId (org.junit.platform.engine.UniqueId)8 Launcher (org.junit.platform.launcher.Launcher)8 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 TestDescriptor (org.junit.platform.engine.TestDescriptor)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)4 TestEngine (org.junit.platform.engine.TestEngine)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4