Search in sources :

Example 26 with TestIdentifier

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

the class XmlReportData method getAncestors.

private List<TestIdentifier> getAncestors(TestIdentifier testIdentifier) {
    TestIdentifier current = testIdentifier;
    List<TestIdentifier> ancestors = new ArrayList<>();
    while (current != null) {
        ancestors.add(current);
        current = this.testPlan.getParent(current).orElse(null);
    }
    return ancestors;
}
Also used : ArrayList(java.util.ArrayList) TestIdentifier(org.junit.platform.launcher.TestIdentifier)

Example 27 with TestIdentifier

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

the class XmlReportWriter method writeTestsuite.

private void writeTestsuite(TestIdentifier testIdentifier, Map<TestIdentifier, AggregatedTestResult> tests, XMLStreamWriter writer) throws XMLStreamException {
    // NumberFormat is not thread-safe. Thus, we instantiate it here and pass it to
    // writeTestcase instead of using a constant
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    writer.writeStartElement("testsuite");
    writeSuiteAttributes(testIdentifier, tests.values(), numberFormat, writer);
    newLine(writer);
    writeSystemProperties(writer);
    for (Entry<TestIdentifier, AggregatedTestResult> entry : tests.entrySet()) {
        writeTestcase(entry.getKey(), entry.getValue(), numberFormat, writer);
    }
    writeOutputElement("system-out", formatNonStandardAttributesAsString(testIdentifier), writer);
    writer.writeEndElement();
    newLine(writer);
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) NumberFormat(java.text.NumberFormat)

Example 28 with TestIdentifier

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

the class StreamInterceptingTestExecutionListenerIntegrationTests method interceptsStream.

@ParameterizedTest(name = "{0}")
@MethodSource("systemStreams")
@ExtendWith(HiddenSystemOutAndErr.class)
void interceptsStream(String configParam, Supplier<PrintStream> printStreamSupplier, String reportKey) {
    var engine = new DemoHierarchicalTestEngine("engine");
    TestDescriptor test = engine.addTest("test", () -> printStreamSupplier.get().print("4567890"));
    var listener = mock(TestExecutionListener.class);
    doAnswer(invocation -> {
        TestIdentifier testIdentifier = invocation.getArgument(0);
        if (testIdentifier.getUniqueId().equals(test.getUniqueId().toString())) {
            printStreamSupplier.get().print("123");
        }
        return null;
    }).when(listener).executionStarted(any());
    var launcher = createLauncher(engine);
    var discoveryRequest = // 
    request().selectors(// 
    selectUniqueId(test.getUniqueId())).configurationParameter(configParam, // 
    String.valueOf(true)).configurationParameter(LauncherConstants.CAPTURE_MAX_BUFFER_PROPERTY_NAME, // 
    String.valueOf(5)).build();
    launcher.execute(discoveryRequest, listener);
    var testPlanArgumentCaptor = ArgumentCaptor.forClass(TestPlan.class);
    var inOrder = inOrder(listener);
    inOrder.verify(listener).testPlanExecutionStarted(testPlanArgumentCaptor.capture());
    var testPlan = testPlanArgumentCaptor.getValue();
    var testIdentifier = testPlan.getTestIdentifier(test.getUniqueId().toString());
    var reportEntryArgumentCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    inOrder.verify(listener).reportingEntryPublished(same(testIdentifier), reportEntryArgumentCaptor.capture());
    inOrder.verify(listener).executionFinished(testIdentifier, successful());
    var reportEntry = reportEntryArgumentCaptor.getValue();
    assertThat(reportEntry.getKeyValuePairs()).containsExactly(entry(reportKey, "12345"));
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptor(org.junit.platform.engine.TestDescriptor) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 29 with TestIdentifier

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

the class UniqueIdTrackingListenerIntegrationTests method executeTests.

private static List<String> executeTests(Map<String, String> configurationParameters, ClassSelector... classSelectors) {
    List<String> uniqueIds = new ArrayList<>();
    LauncherDiscoveryRequest request = // 
    request().selectors(// 
    classSelectors).filters(// 
    includeEngines("junit-jupiter")).configurationParameters(// 
    configurationParameters).build();
    LauncherFactory.create().execute(request, new TestExecutionListener() {

        @Override
        public void executionSkipped(TestIdentifier testIdentifier, String reason) {
            if (testIdentifier.isTest()) {
                uniqueIds.add(testIdentifier.getUniqueId());
            }
        }

        @Override
        public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
            if (testIdentifier.isTest()) {
                uniqueIds.add(testIdentifier.getUniqueId());
            }
        }
    });
    return uniqueIds;
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ArrayList(java.util.ArrayList) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult)

Example 30 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project intellij-community by JetBrains.

the class JUnit5TestExecutionListener method sendTreeUnderRoot.

private void sendTreeUnderRoot(TestPlan testPlan, TestIdentifier root, HashSet<TestIdentifier> visited) {
    final String idAndName = idAndName(root);
    if (root.isContainer()) {
        myPrintStream.println("##teamcity[suiteTreeStarted" + idAndName + " " + getLocationHint(root) + "]");
        for (TestIdentifier childIdentifier : testPlan.getChildren(root)) {
            if (visited.add(childIdentifier)) {
                sendTreeUnderRoot(testPlan, childIdentifier, visited);
            } else {
                System.err.println("Identifier \'" + childIdentifier.getUniqueId() + "\' is reused");
            }
        }
        myPrintStream.println("##teamcity[suiteTreeEnded" + idAndName + "]");
    } else if (root.isTest()) {
        myPrintStream.println("##teamcity[suiteTreeNode " + idAndName + " " + getLocationHint(root) + "]");
    }
}
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