Search in sources :

Example 56 with UniqueId

use of org.junit.platform.engine.UniqueId in project intellij-community by JetBrains.

the class JUnit5NavigationTest method methodNavigation.

@Test
void methodNavigation() throws Exception {
    UniqueId uniqueId = UniqueId.parse("[class:JUnit5NavigationTest]/[method:methodNavigation]");
    MethodTestDescriptor methodTestDescriptor = new MethodTestDescriptor(uniqueId, JUnit5NavigationTest.class, JUnit5NavigationTest.class.getDeclaredMethod("methodNavigation"));
    TestIdentifier testIdentifier = TestIdentifier.from(methodTestDescriptor);
    Assertions.assertEquals(JUnit5NavigationTest.class.getName(), JUnit5TestExecutionListener.getClassName(testIdentifier));
    Assertions.assertEquals("methodNavigation", JUnit5TestExecutionListener.getMethodName(testIdentifier));
//Assertions.assertEquals("methodNavigation", testIdentifier.getDisplayName()); todo methodNavigation()
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 57 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 58 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 59 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 60 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)

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