Search in sources :

Example 6 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class TestIdentifierTests method inheritsTypeFromDescriptor.

@Test
void inheritsTypeFromDescriptor() {
    TestDescriptor descriptor = new TestDescriptorStub(UniqueId.root("aType", "uniqueId"), "displayName");
    var 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.fakes.TestDescriptorStub) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 7 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class TestIdentifierTests method inheritsIdAndNamesFromDescriptor.

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

Example 8 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class EngineDiscoveryResultValidatorTests method detectCycleWithDoubleTest.

@Test
void detectCycleWithDoubleTest() {
    var rootId = UniqueId.forEngine("root");
    var root = new TestDescriptorStub(rootId, "root");
    TestDescriptor group1 = new TestDescriptorStub(rootId.append("group", "1"), "1");
    TestDescriptor group2 = new TestDescriptorStub(rootId.append("group", "2"), "2");
    root.addChild(group1);
    root.addChild(group2);
    TestDescriptor test1 = new TestDescriptorStub(rootId.append("test", "1"), "1-1");
    TestDescriptor test2 = new TestDescriptorStub(rootId.append("test", "2"), "2-2");
    group1.addChild(test1);
    group2.addChild(test2);
    assertTrue(validator.isAcyclic(root));
    group2.addChild(test1);
    assertFalse(validator.isAcyclic(root));
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 9 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class EngineDiscoveryResultValidatorTests method detectCycleWithDoubleGroup.

@Test
void detectCycleWithDoubleGroup() {
    var rootId = UniqueId.forEngine("root");
    var root = new TestDescriptorStub(rootId, "root");
    TestDescriptor group1 = new TestDescriptorStub(rootId.append("group", "1"), "1");
    TestDescriptor group2 = new TestDescriptorStub(rootId.append("group", "2"), "2");
    root.addChild(group1);
    root.addChild(group2);
    assertTrue(validator.isAcyclic(root));
    group2.addChild(group1);
    assertFalse(validator.isAcyclic(root));
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 10 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class DefaultLauncherTests method reportsDynamicTestDescriptorsCorrectly.

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

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            var 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);
            var listener = request.getEngineExecutionListener();
            listener.executionStarted(request.getRootTestDescriptor());
            var containerAndTest = getOnlyElement(request.getRootTestDescriptor().getChildren());
            listener.executionStarted(containerAndTest);
            var 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());
        }
    };
    var launcher = createLauncher(engine);
    var listener = mock(TestExecutionListener.class);
    launcher.execute(request().build(), listener);
    var inOrder = inOrder(listener);
    var testPlanArgumentCaptor = ArgumentCaptor.forClass(TestPlan.class);
    inOrder.verify(listener).testPlanExecutionStarted(testPlanArgumentCaptor.capture());
    var testPlan = testPlanArgumentCaptor.getValue();
    var engineTestIdentifier = testPlan.getTestIdentifier(engineId.toString());
    var containerAndTestIdentifier = testPlan.getTestIdentifier(containerAndTestId.toString());
    var 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 : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineSpy(org.junit.platform.fakes.TestEngineSpy) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TestDescriptorStub (org.junit.platform.fakes.TestDescriptorStub)22 Test (org.junit.jupiter.api.Test)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)6 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 TestEngineSpy (org.junit.platform.fakes.TestEngineSpy)3 StringWriter (java.io.StringWriter)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestEngine (org.junit.platform.engine.TestEngine)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)2 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)2 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1