Search in sources :

Example 46 with UniqueId

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

the class EngineDiscoveryRequestResolution method resolveCompletely.

private void resolveCompletely(DiscoverySelector selector) {
    EngineDiscoveryListener discoveryListener = request.getDiscoveryListener();
    UniqueId engineId = engineDescriptor.getUniqueId();
    try {
        Optional<Resolution> result = resolve(selector);
        if (result.isPresent()) {
            discoveryListener.selectorProcessed(engineId, selector, resolved());
            enqueueAdditionalSelectors(result.get());
        } else {
            discoveryListener.selectorProcessed(engineId, selector, unresolved());
        }
    } catch (Throwable t) {
        UnrecoverableExceptions.rethrowIfUnrecoverable(t);
        discoveryListener.selectorProcessed(engineId, selector, failed(t));
    }
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) EngineDiscoveryListener(org.junit.platform.engine.EngineDiscoveryListener) Resolution(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution)

Example 47 with UniqueId

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

the class RunListenerAdapter method registerDynamicTestDescriptor.

private VintageTestDescriptor registerDynamicTestDescriptor(Description description, Function<Description, Optional<VintageTestDescriptor>> lookup) {
    // workaround for dynamic children as used by Spock's Runner
    TestDescriptor parent = findParent(description, lookup);
    UniqueId uniqueId = parent.getUniqueId().append(SEGMENT_TYPE_DYNAMIC, uniqueIdExtractor.apply(description));
    VintageTestDescriptor dynamicDescriptor = new VintageTestDescriptor(uniqueId, description, testSourceProvider.findTestSource(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 48 with UniqueId

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

the class RunnerTestDescriptorPostProcessor method addChildrenRecursively.

private void addChildrenRecursively(VintageTestDescriptor parent) {
    if (parent.getDescription().isTest()) {
        return;
    }
    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, testSourceProvider.findTestSource(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 49 with UniqueId

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

the class EngineTestKit method executeDirectly.

private static void executeDirectly(TestEngine testEngine, EngineDiscoveryRequest discoveryRequest, EngineExecutionListener listener) {
    UniqueId engineUniqueId = UniqueId.forEngine(testEngine.getId());
    TestDescriptor engineTestDescriptor = testEngine.discover(discoveryRequest, engineUniqueId);
    ExecutionRequest request = new ExecutionRequest(engineTestDescriptor, listener, discoveryRequest.getConfigurationParameters());
    testEngine.execute(request);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 50 with UniqueId

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

the class UniqueIdParsingForArrayParameterIntegrationTests method executeTestsForPrimitiveArrayMethodInjectionCases.

@Test
void executeTestsForPrimitiveArrayMethodInjectionCases() {
    EngineExecutionResults executionResults = executeTestsForClass(PrimitiveArrayMethodInjectionTestCase.class);
    assertEquals(1, executionResults.testEvents().started().count(), "# tests started");
    assertEquals(1, executionResults.testEvents().succeeded().count(), "# tests succeeded");
    assertEquals(0, executionResults.testEvents().failed().count(), "# tests failed");
    // @formatter:off
    UniqueId uniqueId = executionResults.allEvents().map(Event::getTestDescriptor).distinct().skip(2).map(TestDescriptor::getUniqueId).findFirst().orElseThrow(AssertionError::new);
    // @formatter:on
    assertThat(UniqueId.parse(uniqueId.toString())).isEqualTo(uniqueId);
}
Also used : EngineExecutionResults(org.junit.platform.testkit.engine.EngineExecutionResults) UniqueId(org.junit.platform.engine.UniqueId) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

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