Search in sources :

Example 31 with UniqueId

use of org.junit.platform.engine.UniqueId 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 32 with UniqueId

use of org.junit.platform.engine.UniqueId in project cucumber-jvm by cucumber.

the class CucumberTestEngineTest method createExecutionContext.

@Test
void createExecutionContext() {
    EngineExecutionListener listener = new EmptyEngineExecutionListener();
    ConfigurationParameters configuration = new EmptyConfigurationParameters();
    EngineDiscoveryRequest discoveryRequest = new EmptyEngineDiscoveryRequest(configuration);
    UniqueId id = UniqueId.forEngine(engine.getId());
    TestDescriptor testDescriptor = engine.discover(discoveryRequest, id);
    ExecutionRequest execution = new ExecutionRequest(testDescriptor, listener, configuration);
    assertNotNull(engine.createExecutionContext(execution));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 33 with UniqueId

use of org.junit.platform.engine.UniqueId in project cucumber-jvm by cucumber.

the class DiscoverySelectorResolverTest method before.

@BeforeEach
void before() {
    LoggerFactory.addListener(logRecordListener);
    UniqueId id = UniqueId.forEngine(new CucumberTestEngine().getId());
    testDescriptor = new CucumberEngineDescriptor(id);
    assertEquals(0, testDescriptor.getChildren().size());
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 34 with UniqueId

use of org.junit.platform.engine.UniqueId in project graylog2-server by Graylog2.

the class ContainerMatrixClassSelectorResolver method resolve.

@Override
public Resolution resolve(UniqueIdSelector selector, Context context) {
    UniqueId uniqueId = selector.getUniqueId();
    UniqueId.Segment lastSegment = uniqueId.getLastSegment();
    if (ContainerMatrixTestClassDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String className = lastSegment.getValue();
        return ReflectionUtils.tryToLoadClass(className).toOptional().filter(isTestClassWithTests).map(testClass -> toResolution(context.addToParent(parent -> Optional.of(newClassTestDescriptor(parent, testClass))))).orElse(unresolved());
    }
    if (NestedClassTestDescriptor.SEGMENT_TYPE.equals(lastSegment.getType())) {
        String simpleClassName = lastSegment.getValue();
        return toResolution(context.addToParent(() -> selectUniqueId(uniqueId.removeLastSegment()), parent -> {
            if (parent instanceof ClassBasedTestDescriptor) {
                Class<?> parentTestClass = ((ClassBasedTestDescriptor) parent).getTestClass();
                return ReflectionUtils.findNestedClasses(parentTestClass, isNestedTestClass.and(where(Class::getSimpleName, isEqual(simpleClassName)))).stream().findFirst().flatMap(testClass -> Optional.of(newNestedClassTestDescriptor(parent, testClass)));
            }
            return Optional.empty();
        }));
    }
    return unresolved();
}
Also used : IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) IsTestClassWithTests(org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ReflectionUtils.findMethods(org.junit.platform.commons.util.ReflectionUtils.findMethods) ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Collectors.toCollection(java.util.stream.Collectors.toCollection) IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass.isTestOrTestFactoryOrTestTemplateMethod) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass) MongodbServer(org.graylog.testing.containermatrix.MongodbServer) Resolution.unresolved(org.junit.platform.engine.support.discovery.SelectorResolver.Resolution.unresolved) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) Method(java.lang.reflect.Method) LinkedHashSet(java.util.LinkedHashSet) Lifecycle(org.graylog.testing.completebackend.Lifecycle) DiscoverySelector(org.junit.platform.engine.DiscoverySelector) ContainerMatrixTestClassDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor) Predicate(java.util.function.Predicate) Set(java.util.Set) Predicate.isEqual(java.util.function.Predicate.isEqual) UniqueId(org.junit.platform.engine.UniqueId) ReflectionSupport.findNestedClasses(org.junit.platform.commons.support.ReflectionSupport.findNestedClasses) SearchVersion(org.graylog2.storage.SearchVersion) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) ContainerMatrixTestEngine(org.graylog.testing.containermatrix.ContainerMatrixTestEngine) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) NestedClassSelector(org.junit.platform.engine.discovery.NestedClassSelector) List(java.util.List) Stream(java.util.stream.Stream) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) Optional(java.util.Optional) TestDescriptor(org.junit.platform.engine.TestDescriptor) SelectorResolver(org.junit.platform.engine.support.discovery.SelectorResolver) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) FunctionUtils.where(org.junit.platform.commons.util.FunctionUtils.where) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) ClassBasedTestDescriptor(org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor) IsContainerMatrixTestClass(org.graylog.testing.containermatrix.discovery.IsContainerMatrixTestClass) IsNestedTestClass(org.junit.jupiter.engine.discovery.predicates.IsNestedTestClass)

Example 35 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)

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