Search in sources :

Example 11 with TestDescriptorStub

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

the class XmlReportDataTests method resultOfTestIdentifierWithoutReportedEventsIsFailureOfAncestor.

@Test
void resultOfTestIdentifierWithoutReportedEventsIsFailureOfAncestor() {
    EngineDescriptor engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    TestExecutionResult failureOfAncestor = failed(new RuntimeException("failed!"));
    reportData.markFinished(testPlan.getTestIdentifier("[engine:engine]"), failureOfAncestor);
    Optional<TestExecutionResult> result = reportData.getResult(testPlan.getTestIdentifier("[child:test]"));
    assertThat(result).contains(failureOfAncestor);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Test(org.junit.jupiter.api.Test)

Example 12 with TestDescriptorStub

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

the class XmlReportWriterTests method writesEmptySkippedElementForSkippedTestWithoutReason.

@Test
void writesEmptySkippedElementForSkippedTestWithoutReason() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "skippedTest"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markSkipped(testPlan.getTestIdentifier(uniqueId.toString()), null);
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testcase name=\"skippedTest\"", "<skipped/>", "</testcase>");
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 13 with TestDescriptorStub

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

the class XmlReportWriterTests method omitsMessageAttributeForFailedTestWithThrowableWithoutMessage.

@Test
void omitsMessageAttributeForFailedTestWithThrowableWithoutMessage() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "failedTest"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(new NullPointerException()));
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testcase name=\"failedTest\"", "<error type=\"java.lang.NullPointerException\">", "</testcase>");
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 14 with TestDescriptorStub

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

the class TestDescriptorTests method isRootWithParent.

@Test
void isRootWithParent() {
    TestDescriptor child = new TestDescriptorStub(UniqueId.root("child", "child"), "child");
    child.setParent(new TestDescriptorStub(UniqueId.root("root", "root"), "root"));
    assertFalse(child.isRoot());
}
Also used : TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 15 with TestDescriptorStub

use of org.junit.platform.engine.test.TestDescriptorStub 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

TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)18 Test (org.junit.jupiter.api.Test)16 TestPlan (org.junit.platform.launcher.TestPlan)11 UniqueId (org.junit.platform.engine.UniqueId)7 TestIdentifier (org.junit.platform.launcher.TestIdentifier)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)3 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestSource (org.junit.platform.engine.TestSource)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)2 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)2 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1