Search in sources :

Example 6 with TestDescriptor

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

the class RunListenerAdapterTests method newSourcelessChildIdentifierWithParent.

private static TestIdentifier newSourcelessChildIdentifierWithParent(TestPlan testPlan, String parentDisplay, TestSource parentTestSource) {
    // A parent test identifier with a name.
    TestDescriptor parent = mock(TestDescriptor.class);
    when(parent.getUniqueId()).thenReturn(newId());
    when(parent.getDisplayName()).thenReturn(parentDisplay);
    when(parent.getLegacyReportingName()).thenReturn(parentDisplay);
    when(parent.getSource()).thenReturn(Optional.ofNullable(parentTestSource));
    when(parent.getType()).thenReturn(Type.CONTAINER);
    TestIdentifier parentId = TestIdentifier.from(parent);
    // The (child) test case that is to be executed as part of a test plan.
    TestDescriptor child = mock(TestDescriptor.class);
    when(child.getUniqueId()).thenReturn(newId());
    when(child.getType()).thenReturn(Type.TEST);
    when(child.getLegacyReportingName()).thenReturn("child");
    // Ensure the child source is null yet that there is a parent -- the special case to be tested.
    when(child.getSource()).thenReturn(Optional.empty());
    when(child.getParent()).thenReturn(Optional.of(parent));
    TestIdentifier childId = TestIdentifier.from(child);
    testPlan.add(childId);
    testPlan.add(parentId);
    return childId;
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 7 with TestDescriptor

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

the class DefaultLauncher method execute.

private void execute(Root root, ConfigurationParameters configurationParameters, TestExecutionListener... listeners) {
    TestExecutionListenerRegistry listenerRegistry = buildListenerRegistryForExecution(listeners);
    TestPlan testPlan = TestPlan.from(root.getEngineDescriptors());
    TestExecutionListener testExecutionListener = listenerRegistry.getCompositeTestExecutionListener();
    testExecutionListener.testPlanExecutionStarted(testPlan);
    ExecutionListenerAdapter engineExecutionListener = new ExecutionListenerAdapter(testPlan, testExecutionListener);
    for (TestEngine testEngine : root.getTestEngines()) {
        TestDescriptor testDescriptor = root.getTestDescriptorFor(testEngine);
        execute(testEngine, new ExecutionRequest(testDescriptor, engineExecutionListener, configurationParameters));
    }
    testExecutionListener.testPlanExecutionFinished(testPlan);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestEngine(org.junit.platform.engine.TestEngine) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 8 with TestDescriptor

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

the class ExecutionEventRecorder method execute.

public static void execute(TestEngine testEngine, EngineDiscoveryRequest discoveryRequest, EngineExecutionListener listener) {
    TestDescriptor engineTestDescriptor = testEngine.discover(discoveryRequest, UniqueId.forEngine(testEngine.getId()));
    testEngine.execute(new ExecutionRequest(engineTestDescriptor, listener, discoveryRequest.getConfigurationParameters()));
}
Also used : ExecutionRequest(org.junit.platform.engine.ExecutionRequest) ExecutionEvent.byTestDescriptor(org.junit.platform.engine.test.event.ExecutionEvent.byTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 9 with TestDescriptor

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

the class DiscoveryFilterApplierTests method nestedTestClassesAreAlwaysIncludedWhenTheirParentIs.

@Test
void nestedTestClassesAreAlwaysIncludedWhenTheirParentIs() {
    // @formatter:off
    TestDescriptor engineDescriptor = engineDescriptor().with(classTestDescriptor("matching", MatchingClass.class).with(nestedClassTestDescriptor("nested", MatchingClass.NestedClass.class))).build();
    applyClassNamePredicate(engineDescriptor, includeClassNamePatterns(".*\\$MatchingClass"));
    assertThat(engineDescriptor.getDescendants()).extracting(TestDescriptor::getUniqueId).containsExactlyInAnyOrder(UniqueId.root("class", "matching"), UniqueId.root("nested-class", "nested"));
// @formatter:on
}
Also used : TestDescriptorBuilder.classTestDescriptor(org.junit.jupiter.engine.descriptor.TestDescriptorBuilder.classTestDescriptor) TestDescriptorBuilder.nestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.TestDescriptorBuilder.nestedClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 10 with TestDescriptor

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

the class DiscoveryFilterApplierTests method nonMatchingClassesAreExcluded.

@Test
void nonMatchingClassesAreExcluded() {
    // @formatter:off
    TestDescriptor engineDescriptor = engineDescriptor().with(classTestDescriptor("matching", MatchingClass.class), classTestDescriptor("other", OtherClass.class)).build();
    applyClassNamePredicate(engineDescriptor, includeClassNamePatterns(".*\\$MatchingClass"));
    assertThat(engineDescriptor.getDescendants()).extracting(TestDescriptor::getUniqueId).containsExactly(UniqueId.root("class", "matching"));
// @formatter:on
}
Also used : TestDescriptorBuilder.classTestDescriptor(org.junit.jupiter.engine.descriptor.TestDescriptorBuilder.classTestDescriptor) TestDescriptorBuilder.nestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.TestDescriptorBuilder.nestedClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

TestDescriptor (org.junit.platform.engine.TestDescriptor)143 Test (org.junit.jupiter.api.Test)103 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)58 UniqueId (org.junit.platform.engine.UniqueId)33 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)31 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)19 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)17 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)14 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Set (java.util.Set)11 DynamicTest (org.junit.jupiter.api.DynamicTest)11 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)11 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)11 Optional (java.util.Optional)10 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)9 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)9