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;
}
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);
}
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"));
}
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;
}
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) + "]");
}
}
Aggregations