Search in sources :

Example 41 with TestIdentifier

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

the class DefaultLauncherTests method discoverTestPlanForSingleEngine.

@Test
void discoverTestPlanForSingleEngine() {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("myEngine");
    engine.addTest("test1", noOp);
    engine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(engine);
    TestPlan testPlan = launcher.discover(request().selectors(selectPackage("any")).build());
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier rootIdentifier = testPlan.getRoots().iterator().next();
    assertThat(testPlan.getChildren(rootIdentifier.getUniqueId())).hasSize(2);
    assertThat(testPlan.getChildren("[engine:myEngine]")).hasSize(2);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 42 with TestIdentifier

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

the class RunListenerAdapterTests method notifiedWithCorrectNamesWhenMethodExecutionStarted.

@Test
void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exception {
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(testPlan);
    TestIdentifier methodIdentifier = identifiersAsParentOnTestPlan(testPlan, newClassDescriptor(), newMethodDescriptor());
    adapter.executionStarted(methodIdentifier);
    verify(listener).testStarting(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertEquals(MY_TEST_METHOD_NAME, entry.getName());
    assertEquals(MyTestClass.class.getName(), entry.getSourceName());
    assertNull(entry.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 43 with TestIdentifier

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

the class RunListenerAdapterTests method displayNamesIgnoredInReport.

@Test
void displayNamesIgnoredInReport() throws NoSuchMethodException {
    TestMethodTestDescriptor descriptor = new TestMethodTestDescriptor(newId(), MyTestClass.class, MyTestClass.class.getDeclaredMethod("myNamedTestMethod"));
    TestIdentifier factoryIdentifier = TestIdentifier.from(descriptor);
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    adapter.executionSkipped(factoryIdentifier, "");
    verify(listener).testSkipped(entryCaptor.capture());
    ReportEntry value = entryCaptor.getValue();
    assertEquals("myNamedTestMethod", value.getName());
}
Also used : ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 44 with TestIdentifier

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

the class RunListenerAdapterTests method notifiedWithCompatibleNameForMethodWithArguments.

@Test
void notifiedWithCompatibleNameForMethodWithArguments() throws Exception {
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(testPlan);
    TestIdentifier methodIdentifier = identifiersAsParentOnTestPlan(testPlan, newClassDescriptor(), newMethodDescriptor(String.class));
    adapter.executionStarted(methodIdentifier);
    verify(listener).testStarting(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertEquals(MY_TEST_METHOD_NAME + "{String}", entry.getName());
    assertEquals(MyTestClass.class.getName(), entry.getSourceName());
    assertNull(entry.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 45 with TestIdentifier

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

the class RunListenerAdapterTests method identifiersAsParentOnTestPlan.

private static TestIdentifier identifiersAsParentOnTestPlan(TestPlan plan, TestDescriptor parent, TestDescriptor child) {
    child.setParent(parent);
    TestIdentifier parentIdentifier = TestIdentifier.from(parent);
    TestIdentifier childIdentifier = TestIdentifier.from(child);
    plan.add(parentIdentifier);
    plan.add(childIdentifier);
    return childIdentifier;
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier)

Aggregations

TestIdentifier (org.junit.platform.launcher.TestIdentifier)53 Test (org.junit.jupiter.api.Test)29 TestPlan (org.junit.platform.launcher.TestPlan)23 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)17 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)7 LinkedHashMap (java.util.LinkedHashMap)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 Map (java.util.Map)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)5 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)3 MethodTestDescriptor (org.junit.jupiter.engine.descriptor.MethodTestDescriptor)3 Launcher (org.junit.platform.launcher.Launcher)3