Search in sources :

Example 86 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class LegacyReportingUtilsTest method legacyReportingClassNameForDescendantOfTestIdentifierWithClassSourceIsClassName.

@Test
void legacyReportingClassNameForDescendantOfTestIdentifierWithClassSourceIsClassName() {
    UniqueId classUniqueId = engineDescriptor.getUniqueId().append("class", "class");
    TestDescriptor classDescriptor = createTestDescriptor(classUniqueId, "Class", ClassSource.from(LegacyReportingUtilsTest.class));
    engineDescriptor.addChild(classDescriptor);
    UniqueId subUniqueId = classUniqueId.append("sub", "baz");
    TestDescriptor subDescriptor = createTestDescriptor(subUniqueId, "Baz", null);
    classDescriptor.addChild(subDescriptor);
    UniqueId subSubUniqueId = subUniqueId.append("subsub", "qux");
    TestDescriptor subSubDescriptor = createTestDescriptor(subSubUniqueId, "Qux", null);
    subDescriptor.addChild(subSubDescriptor);
    assertThat(getClassName(engineDescriptor.getUniqueId())).isEqualTo("<unrooted>");
    assertThat(getClassName(classUniqueId)).isEqualTo(LegacyReportingUtilsTest.class.getName());
    assertThat(getClassName(subUniqueId)).isEqualTo(LegacyReportingUtilsTest.class.getName());
    assertThat(getClassName(subSubUniqueId)).isEqualTo(LegacyReportingUtilsTest.class.getName());
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 87 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class LegacyReportingUtilsTest method legacyReportingClassNameForTestIdentifierWithoutClassSourceIsParentLegacyReportingName.

@Test
void legacyReportingClassNameForTestIdentifierWithoutClassSourceIsParentLegacyReportingName() {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("child", "bar");
    TestDescriptor testDescriptor = createTestDescriptor(uniqueId, "Bar", null);
    engineDescriptor.addChild(testDescriptor);
    assertThat(getClassName(engineDescriptor.getUniqueId())).isEqualTo("<unrooted>");
    assertThat(getClassName(uniqueId)).isEqualTo("Foo");
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 88 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class DefaultLauncher method discoverEngineRoot.

private Optional<TestDescriptor> discoverEngineRoot(TestEngine testEngine, LauncherDiscoveryRequest discoveryRequest) {
    UniqueId uniqueEngineId = UniqueId.forEngine(testEngine.getId());
    try {
        TestDescriptor engineRoot = testEngine.discover(discoveryRequest, uniqueEngineId);
        Preconditions.notNull(engineRoot, () -> String.format("The discover() method for TestEngine with ID '%s' must return a non-null root TestDescriptor.", testEngine.getId()));
        return Optional.of(engineRoot);
    } catch (Throwable throwable) {
        handleThrowable(testEngine, "discover", throwable);
        return Optional.empty();
    }
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 89 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class TestClassRequestResolver method addChildrenRecursively.

private void addChildrenRecursively(VintageTestDescriptor parent) {
    List<Description> children = parent.getDescription().getChildren();
    // Use LinkedHashMap to preserve order, ArrayList for fast access by index
    Map<String, List<Description>> childrenByUniqueId = children.stream().collect(groupingBy(uniqueIdReader.andThen(uniqueIdStringifier), LinkedHashMap::new, toCollection(ArrayList::new)));
    for (Entry<String, List<Description>> entry : childrenByUniqueId.entrySet()) {
        String uniqueId = entry.getKey();
        List<Description> childrenWithSameUniqueId = entry.getValue();
        IntFunction<String> uniqueIdGenerator = determineUniqueIdGenerator(uniqueId, childrenWithSameUniqueId);
        for (int index = 0; index < childrenWithSameUniqueId.size(); index++) {
            String reallyUniqueId = uniqueIdGenerator.apply(index);
            Description description = childrenWithSameUniqueId.get(index);
            UniqueId id = parent.getUniqueId().append(VintageTestDescriptor.SEGMENT_TYPE_TEST, reallyUniqueId);
            VintageTestDescriptor child = new VintageTestDescriptor(id, description);
            parent.addChild(child);
            addChildrenRecursively(child);
        }
    }
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 90 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class TestClassRequestResolver method createCompleteRunnerTestDescriptor.

private RunnerTestDescriptor createCompleteRunnerTestDescriptor(Class<?> testClass, Runner runner, UniqueId engineId) {
    UniqueId id = engineId.append(SEGMENT_TYPE_RUNNER, testClass.getName());
    RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(id, testClass, runner);
    addChildrenRecursively(runnerTestDescriptor);
    return runnerTestDescriptor;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)131 Test (org.junit.jupiter.api.Test)95 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)83 DynamicTest (org.junit.jupiter.api.DynamicTest)64 TestDescriptor (org.junit.platform.engine.TestDescriptor)29 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)25 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)15 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)14 List (java.util.List)9 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)8 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)8 TestPlan (org.junit.platform.launcher.TestPlan)8 JUnitException (org.junit.platform.commons.JUnitException)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)6 TestEngine (org.junit.platform.engine.TestEngine)6 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5