Search in sources :

Example 1 with EngineDiscoveryRequest

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

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

the class TestClassWithTemplate method resolvingUniqueIdWithWrongParamsResolvesNothing.

@Test
@TrackLogRecords
void resolvingUniqueIdWithWrongParamsResolvesNothing(LogRecordListener listener) {
    UniqueId uniqueId = uniqueIdForMethod(HerTestClass.class, "test7(java.math.BigDecimal)");
    EngineDiscoveryRequest request = request().selectors(selectUniqueId(uniqueId)).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    // 
    assertThat(listener.stream(JavaElementsResolver.class, Level.WARNING).map(LogRecord::getMessage)).contains("Unique ID '" + uniqueId + "' could only be partially resolved. " + "All resolved segments will be executed; however, the following segments " + "could not be resolved: [Segment [type = 'method', value = 'test7(java.math.BigDecimal)']]");
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LogRecord(java.util.logging.LogRecord) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 3 with EngineDiscoveryRequest

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

the class TestClassWithTemplate method resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing.

@Test
@TrackLogRecords
void resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing(LogRecordListener listener) {
    UniqueId uniqueId = engineId().append("bogus", "enigma");
    UniqueIdSelector selector = selectUniqueId(uniqueId);
    EngineDiscoveryRequest request = request().selectors(selector).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    // 
    assertThat(listener.stream(JavaElementsResolver.class, Level.WARNING).map(LogRecord::getMessage)).contains("Unique ID '" + uniqueId + "' could not be resolved.");
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LogRecord(java.util.logging.LogRecord) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 4 with EngineDiscoveryRequest

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

the class TestClassWithTemplate method resolvingSelectorOfNonTestMethodResolvesNothing.

@Test
void resolvingSelectorOfNonTestMethodResolvesNothing() throws NoSuchMethodException {
    Method notATest = MyTestClass.class.getDeclaredMethod("notATest");
    MethodSelector selector = selectMethod(notATest.getDeclaringClass(), notATest);
    EngineDiscoveryRequest request = request().selectors(selector).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
}
Also used : MethodSelector(org.junit.platform.engine.discovery.MethodSelector) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) JupiterUniqueIdBuilder.uniqueIdForMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForMethod) Method(java.lang.reflect.Method) JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod) JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 5 with EngineDiscoveryRequest

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

the class UniqueIdSelectorResolverTests method logsWarningOnUnexpectedTestDescriptor.

@Test
void logsWarningOnUnexpectedTestDescriptor(LogRecordListener listener) {
    UniqueId uniqueId = UniqueId.forEngine(ENGINE_ID).append("wrong-type", "foo:bar");
    EngineDiscoveryRequest request = requestWithSelector(selectUniqueId(uniqueId));
    new UniqueIdSelectorResolver().resolve(request, allClassesPredicate, collector);
    assertNoRequests();
    assertLoggedWarning(listener, "Unresolvable Unique ID (" + uniqueId + "): Unique ID segment after engine segment must be of type \"runner\"");
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Aggregations

EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)13 Test (org.junit.jupiter.api.Test)12 UniqueId (org.junit.platform.engine.UniqueId)7 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)7 DynamicTest (org.junit.jupiter.api.DynamicTest)4 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 LogRecord (java.util.logging.LogRecord)2 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)2 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)2 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)2 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)2 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 Method (java.lang.reflect.Method)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1