Search in sources :

Example 1 with VintageTestDescriptor

use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.

the class TestRunTests method registersDynamicTestDescriptors.

@Test
void registersDynamicTestDescriptors() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
    UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
    RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
    UniqueId dynamicTestId = runnerId.append(SEGMENT_TYPE_DYNAMIC, "dynamicTest");
    Description dynamicDescription = createTestDescription(testClass, "dynamicTest");
    VintageTestDescriptor dynamicTestDescriptor = new VintageTestDescriptor(dynamicTestId, dynamicDescription);
    TestRun testRun = new TestRun(runnerTestDescriptor);
    testRun.registerDynamicTest(dynamicTestDescriptor);
    assertThat(testRun.lookupTestDescriptor(dynamicDescription)).contains(dynamicTestDescriptor);
    assertTrue(testRun.isDescendantOfRunnerTestDescriptor(dynamicTestDescriptor));
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) UniqueId(org.junit.platform.engine.UniqueId) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) Description.createTestDescription(org.junit.runner.Description.createTestDescription) Description(org.junit.runner.Description) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with VintageTestDescriptor

use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.

the class RunListenerAdapter method registerDynamicTestDescriptor.

private VintageTestDescriptor registerDynamicTestDescriptor(Description description) {
    // workaround for dynamic children as used by Spock's Runner
    TestDescriptor parent = findParent(description);
    UniqueId uniqueId = parent.getUniqueId().append(SEGMENT_TYPE_DYNAMIC, uniqueIdExtractor.apply(description));
    VintageTestDescriptor dynamicDescriptor = new VintageTestDescriptor(uniqueId, description);
    parent.addChild(dynamicDescriptor);
    testRun.registerDynamicTest(dynamicDescriptor);
    dynamicTestRegistered(dynamicDescriptor);
    return dynamicDescriptor;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 3 with VintageTestDescriptor

use of org.junit.vintage.engine.descriptor.VintageTestDescriptor in project junit5 by junit-team.

the class TestRunTests method returnsEmptyOptionalForUnknownDescriptions.

@Test
void returnsEmptyOptionalForUnknownDescriptions() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
    UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
    RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
    Description unknownDescription = createTestDescription(testClass, "dynamicTest");
    TestRun testRun = new TestRun(runnerTestDescriptor);
    Optional<VintageTestDescriptor> testDescriptor = testRun.lookupTestDescriptor(unknownDescription);
    assertThat(testDescriptor).isEmpty();
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) UniqueId(org.junit.platform.engine.UniqueId) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) Description.createTestDescription(org.junit.runner.Description.createTestDescription) Description(org.junit.runner.Description) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with VintageTestDescriptor

use of org.junit.vintage.engine.descriptor.VintageTestDescriptor 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)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)4 VintageTestDescriptor (org.junit.vintage.engine.descriptor.VintageTestDescriptor)4 Description (org.junit.runner.Description)3 RunnerTestDescriptor (org.junit.vintage.engine.descriptor.RunnerTestDescriptor)3 Test (org.junit.jupiter.api.Test)2 Description.createTestDescription (org.junit.runner.Description.createTestDescription)2 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)2 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TestDescriptor (org.junit.platform.engine.TestDescriptor)1