Search in sources :

Example 1 with TestDescriptor

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

the class TestIdentifierTests method inheritsIdAndNamesFromDescriptor.

@Test
void inheritsIdAndNamesFromDescriptor() {
    TestDescriptor testDescriptor = new TestDescriptorStub(UniqueId.root("aType", "uniqueId"), "displayName");
    TestIdentifier testIdentifier = TestIdentifier.from(testDescriptor);
    assertEquals("[aType:uniqueId]", testIdentifier.getUniqueId());
    assertEquals("displayName", testIdentifier.getDisplayName());
}
Also used : TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with TestDescriptor

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

the class TestIdentifierTests method inheritsTypeFromDescriptor.

@Test
void inheritsTypeFromDescriptor() {
    TestDescriptor descriptor = new TestDescriptorStub(UniqueId.root("aType", "uniqueId"), "displayName");
    TestIdentifier identifier = TestIdentifier.from(descriptor);
    assertEquals(TestDescriptor.Type.TEST, identifier.getType());
    assertTrue(identifier.isTest());
    assertFalse(identifier.isContainer());
    descriptor.addChild(new TestDescriptorStub(UniqueId.root("aChild", "uniqueId"), "displayName"));
    identifier = TestIdentifier.from(descriptor);
    assertEquals(TestDescriptor.Type.CONTAINER, identifier.getType());
    assertFalse(identifier.isTest());
    assertTrue(identifier.isContainer());
}
Also used : TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with TestDescriptor

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

the class DefaultLauncherTests method launcherWillNotExecuteEnginesExplicitlyIncludedViaMultipleCompetingEngineFilters.

@Test
void launcherWillNotExecuteEnginesExplicitlyIncludedViaMultipleCompetingEngineFilters() {
    DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("first");
    TestDescriptor test1 = firstEngine.addTest("test1", noOp);
    DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("second");
    TestDescriptor test2 = secondEngine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
    // @formatter:off
    TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).filters(includeEngines("first"), includeEngines("second")).build());
    // @formatter:on
    assertThat(testPlan.getRoots()).isEmpty();
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with TestDescriptor

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

the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.

@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            TestDescriptorStub containerDescriptor = new TestDescriptorStub(uniqueId.append("container", "a"), "container") {

                @Override
                public Type getType() {
                    return Type.CONTAINER;
                }
            };
            containerDescriptor.addChild(new TestDescriptorStub(containerDescriptor.getUniqueId().append("test", "b"), "test"));
            engineDescriptor.addChild(containerDescriptor);
            return engineDescriptor;
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestPlan testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier engineIdentifier = getOnlyElement(testPlan.getRoots());
    assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestPlan(org.junit.platform.launcher.TestPlan) EngineFilter.excludeEngines(org.junit.platform.launcher.EngineFilter.excludeEngines) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestExecutionResult.successful(org.junit.platform.engine.TestExecutionResult.successful) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ArgumentCaptor(org.mockito.ArgumentCaptor) LauncherFactoryForTestingPurposesOnly.createLauncher(org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly.createLauncher) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) InOrder(org.mockito.InOrder) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) JUnitException(org.junit.platform.commons.JUnitException) TestEngineStub(org.junit.platform.engine.test.TestEngineStub) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) TestIdentifier(org.junit.platform.launcher.TestIdentifier) PostDiscoveryFilterStub(org.junit.platform.launcher.PostDiscoveryFilterStub) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) Mockito.inOrder(org.mockito.Mockito.inOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) DiscoverySelectors.selectPackage(org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 5 with TestDescriptor

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

the class DefaultLauncherTests method launcherWillExecuteAllEnginesExplicitlyIncludedViaSingleEngineFilter.

@Test
void launcherWillExecuteAllEnginesExplicitlyIncludedViaSingleEngineFilter() {
    DemoHierarchicalTestEngine firstEngine = new DemoHierarchicalTestEngine("first");
    TestDescriptor test1 = firstEngine.addTest("test1", noOp);
    DemoHierarchicalTestEngine secondEngine = new DemoHierarchicalTestEngine("second");
    TestDescriptor test2 = secondEngine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(firstEngine, secondEngine);
    // @formatter:off
    TestPlan testPlan = launcher.discover(request().selectors(selectUniqueId(test1.getUniqueId()), selectUniqueId(test2.getUniqueId())).filters(includeEngines("first", "second")).build());
    // @formatter:on
    assertThat(testPlan.getRoots()).hasSize(2);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

TestDescriptor (org.junit.platform.engine.TestDescriptor)120 Test (org.junit.jupiter.api.Test)96 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)31 UniqueId (org.junit.platform.engine.UniqueId)22 TestPlan (org.junit.platform.launcher.TestPlan)14 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)12 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)10 Optional (java.util.Optional)9 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)9 TestIdentifier (org.junit.platform.launcher.TestIdentifier)9 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)9 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)8 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)8 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)8 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 List (java.util.List)7 DynamicTest (org.junit.jupiter.api.DynamicTest)7