Search in sources :

Example 11 with EngineDiscoveryRequest

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

the class VintageDiscovererTests method classNameFilterExcludesClass.

@Test
void classNameFilterExcludesClass() {
    // @formatter:off
    EngineDiscoveryRequest request = request().selectors(selectClass(Foo.class), selectClass(Bar.class)).filters(ClassNameFilter.includeClassNamePatterns(".*Foo")).build();
    // @formatter:on
    VintageDiscoverer discoverer = new VintageDiscoverer();
    TestDescriptor testDescriptor = discoverer.discover(request, engineId());
    assertThat(testDescriptor.getChildren()).hasSize(1);
    assertThat(getOnlyElement(testDescriptor.getChildren()).getUniqueId().toString()).contains(Foo.class.getName());
}
Also used : EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with EngineDiscoveryRequest

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

the class TestClassWithTemplate method resolvingUniqueIdOfNonTestMethodResolvesNothing.

@Test
void resolvingUniqueIdOfNonTestMethodResolvesNothing() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(MyTestClass.class, "notATest()"));
    EngineDiscoveryRequest request = request().selectors(selector).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 13 with EngineDiscoveryRequest

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

the class DefaultLauncherTests method reportsDynamicTestDescriptorsCorrectly.

@Test
void reportsDynamicTestDescriptorsCorrectly() {
    UniqueId engineId = UniqueId.forEngine(TestEngineSpy.ID);
    UniqueId containerAndTestId = engineId.append("c&t", "c&t");
    UniqueId dynamicTestId = containerAndTestId.append("test", "test");
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            engineDescriptor.addChild(new TestDescriptorStub(containerAndTestId, "c&t") {

                @Override
                public Type getType() {
                    return Type.CONTAINER_AND_TEST;
                }
            });
            return engineDescriptor;
        }

        @Override
        public void execute(ExecutionRequest request) {
            super.execute(request);
            EngineExecutionListener listener = request.getEngineExecutionListener();
            listener.executionStarted(request.getRootTestDescriptor());
            TestDescriptor containerAndTest = getOnlyElement(request.getRootTestDescriptor().getChildren());
            listener.executionStarted(containerAndTest);
            TestDescriptorStub dynamicTest = new TestDescriptorStub(dynamicTestId, "test");
            dynamicTest.setParent(containerAndTest);
            listener.dynamicTestRegistered(dynamicTest);
            listener.executionStarted(dynamicTest);
            listener.executionFinished(dynamicTest, successful());
            listener.executionFinished(containerAndTest, successful());
            listener.executionFinished(request.getRootTestDescriptor(), successful());
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestExecutionListener listener = mock(TestExecutionListener.class);
    launcher.execute(request().build(), listener);
    InOrder inOrder = inOrder(listener);
    ArgumentCaptor<TestPlan> testPlanArgumentCaptor = ArgumentCaptor.forClass(TestPlan.class);
    inOrder.verify(listener).testPlanExecutionStarted(testPlanArgumentCaptor.capture());
    TestPlan testPlan = testPlanArgumentCaptor.getValue();
    TestIdentifier engineTestIdentifier = testPlan.getTestIdentifier(engineId.toString());
    TestIdentifier containerAndTestIdentifier = testPlan.getTestIdentifier(containerAndTestId.toString());
    TestIdentifier dynamicTestIdentifier = testPlan.getTestIdentifier(dynamicTestId.toString());
    assertThat(engineTestIdentifier.getParentId()).isEmpty();
    assertThat(containerAndTestIdentifier.getParentId()).contains(engineId.toString());
    assertThat(dynamicTestIdentifier.getParentId()).contains(containerAndTestId.toString());
    inOrder.verify(listener).executionStarted(engineTestIdentifier);
    inOrder.verify(listener).executionStarted(containerAndTestIdentifier);
    inOrder.verify(listener).dynamicTestRegistered(dynamicTestIdentifier);
    inOrder.verify(listener).executionStarted(dynamicTestIdentifier);
    inOrder.verify(listener).executionFinished(dynamicTestIdentifier, successful());
    inOrder.verify(listener).executionFinished(containerAndTestIdentifier, successful());
    inOrder.verify(listener).executionFinished(engineTestIdentifier, successful());
    inOrder.verify(listener).testPlanExecutionFinished(same(testPlan));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) InOrder(org.mockito.InOrder) TestPlan(org.junit.platform.launcher.TestPlan) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestIdentifier(org.junit.platform.launcher.TestIdentifier) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) 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