Search in sources :

Example 36 with UniqueId

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);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor)

Example 37 with UniqueId

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();
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DynamicContainer(org.junit.jupiter.api.DynamicContainer) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 38 with UniqueId

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));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId)

Example 39 with 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");
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) JUnit4TestCaseWithRunnerWithCustomUniqueIds(org.junit.vintage.engine.samples.junit4.JUnit4TestCaseWithRunnerWithCustomUniqueIds) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 40 with UniqueId

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
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)78 Test (org.junit.jupiter.api.Test)59 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)44 DynamicTest (org.junit.jupiter.api.DynamicTest)32 TestDescriptor (org.junit.platform.engine.TestDescriptor)19 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)13 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)12 TestPlan (org.junit.platform.launcher.TestPlan)10 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)8 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)7 List (java.util.List)5 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)4 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)4 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)4 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)4 Optional (java.util.Optional)3