use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class AbstractMethodResolver method createTestDescriptor.
private TestDescriptor createTestDescriptor(TestDescriptor parent, Method method) {
UniqueId uniqueId = createUniqueId(method, parent);
Class<?> testClass = ((ClassTestDescriptor) parent).getTestClass();
return createTestDescriptor(uniqueId, testClass, method);
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class TestFactoryTestDescriptor method createDynamicDescriptor.
static Optional<JupiterTestDescriptor> createDynamicDescriptor(JupiterTestDescriptor parent, DynamicNode node, int index, TestSource source, DynamicDescendantFilter dynamicDescendantFilter) {
UniqueId uniqueId;
Supplier<JupiterTestDescriptor> descriptorCreator;
if (node instanceof DynamicTest) {
DynamicTest test = (DynamicTest) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_TEST_SEGMENT_TYPE, "#" + index);
descriptorCreator = () -> new DynamicTestTestDescriptor(uniqueId, index, test, source);
} else {
DynamicContainer container = (DynamicContainer) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#" + index);
descriptorCreator = () -> new DynamicContainerTestDescriptor(uniqueId, index, container, source, dynamicDescendantFilter);
}
if (dynamicDescendantFilter.test(uniqueId)) {
JupiterTestDescriptor descriptor = descriptorCreator.get();
parent.addChild(descriptor);
return Optional.of(descriptor);
}
return Optional.empty();
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class TestContainerResolver method resolveUniqueId.
@Override
public Optional<TestDescriptor> resolveUniqueId(UniqueId.Segment segment, TestDescriptor parent) {
if (!segment.getType().equals(getSegmentType())) {
return Optional.empty();
}
if (!requiredParentType().isInstance(parent)) {
return Optional.empty();
}
String className = getClassName(parent, segment.getValue());
Optional<Class<?>> optionalContainerClass = ReflectionUtils.loadClass(className);
if (!optionalContainerClass.isPresent()) {
return Optional.empty();
}
Class<?> containerClass = optionalContainerClass.get();
if (!isPotentialCandidate(containerClass)) {
return Optional.empty();
}
UniqueId uniqueId = createUniqueId(containerClass, parent);
return Optional.of(resolveClass(containerClass, uniqueId));
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method usesCustomUniqueIdsWhenPresent.
@Test
void usesCustomUniqueIdsWhenPresent() {
Class<?> testClass = JUnit4TestCaseWithRunnerWithCustomUniqueIds.class;
LauncherDiscoveryRequest request = request().selectors(selectClass(testClass)).build();
TestDescriptor engineDescriptor = discoverTests(request);
TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertRunnerTestDescriptor(runnerDescriptor, testClass);
TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
UniqueId prefix = VintageUniqueIdBuilder.uniqueIdForClass(testClass);
assertThat(childDescriptor.getUniqueId().toString()).startsWith(prefix.toString());
String customUniqueIdValue = childDescriptor.getUniqueId().getSegments().get(2).getType();
assertNotNull(Base64.getDecoder().decode(customUniqueIdValue.getBytes(StandardCharsets.UTF_8)), "is a valid Base64 encoding scheme");
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class XmlReportWriterTests method writesEmptySkippedElementForSkippedTestWithoutReason.
@Test
void writesEmptySkippedElementForSkippedTestWithoutReason() throws Exception {
UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "skippedTest"));
TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
reportData.markSkipped(testPlan.getTestIdentifier(uniqueId.toString()), null);
String content = writeXmlReport(testPlan, reportData);
assertValidAccordingToJenkinsSchema(content);
// @formatter:off
assertThat(content).containsSubsequence("<testcase name=\"skippedTest\"", "<skipped/>", "</testcase>");
// @formatter:on
}
Aggregations