Search in sources :

Example 6 with TestDescriptorStub

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

the class XmlReportWriterTests method writesValidXmlEvenIfExceptionMessageContainsCData.

@Test
void writesValidXmlEvenIfExceptionMessageContainsCData() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    AssertionError assertionError = new AssertionError("<foo><![CDATA[bar]]></foo>");
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<![CDATA[", "<foo><![CDATA[bar]]]]><![CDATA[></foo>", "]]>").doesNotContain(assertionError.getMessage());
// @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 7 with TestDescriptorStub

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

the class XmlReportsWritingListenerTests method writesReportEntriesToSystemOutElement.

@Test
void writesReportEntriesToSystemOutElement(@Root Path tempDirectory, TestReporter testReporter) throws Exception {
    EngineDescriptor engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    StringWriter out = new StringWriter();
    XmlReportsWritingListener listener = new XmlReportsWritingListener(tempDirectory, new PrintWriter(out));
    listener.testPlanExecutionStarted(testPlan);
    TestIdentifier testIdentifier = testPlan.getTestIdentifier("[child:test]");
    listener.executionStarted(testIdentifier);
    listener.reportingEntryPublished(testIdentifier, ReportEntry.from("foo", "bar"));
    Map<String, String> map = new LinkedHashMap<>();
    map.put("bar", "baz");
    map.put("qux", "foo");
    listener.reportingEntryPublished(testIdentifier, ReportEntry.from(map));
    listener.executionFinished(testIdentifier, successful());
    listener.executionFinished(testPlan.getTestIdentifier("[engine:engine]"), successful());
    String content = readValidXmlFile(tempDirectory.resolve("TEST-engine.xml"));
    // testReporter.publishEntry("xml", content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite", "<testcase", "<system-out>", "Report Entry #1 (timestamp: " + Year.now(), "- foo: bar\n", "Report Entry #2 (timestamp: " + Year.now(), "- bar: baz\n", "- qux: foo\n", "</system-out>", "</testcase>", "</testsuite>");
// @formatter:on
}
Also used : StringWriter(java.io.StringWriter) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) PrintWriter(java.io.PrintWriter) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 8 with TestDescriptorStub

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

the class SummaryGenerationTests method canGetListOfFailures.

@Test
void canGetListOfFailures() {
    RuntimeException failedException = new RuntimeException("Pow!");
    TestDescriptorStub testDescriptor = new TestDescriptorStub(UniqueId.root("root", "1"), "failingTest") {

        @Override
        public Optional<TestSource> getSource() {
            return Optional.of(ClassSource.from(Object.class));
        }
    };
    TestIdentifier failingTest = TestIdentifier.from(testDescriptor);
    listener.testPlanExecutionStarted(testPlan);
    listener.executionStarted(failingTest);
    listener.executionFinished(failingTest, TestExecutionResult.failed(failedException));
    listener.testPlanExecutionFinished(testPlan);
    final List<TestExecutionSummary.Failure> failures = listener.getSummary().getFailures();
    assertThat(failures).hasSize(1);
    assertThat(failures.get(0).getException()).isEqualTo(failedException);
    assertThat(failures.get(0).getTestIdentifier()).isEqualTo(failingTest);
}
Also used : TestSource(org.junit.platform.engine.TestSource) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 9 with TestDescriptorStub

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

the class XmlReportDataTests method resultOfTestIdentifierWithoutReportedEventsIsEmptyWhenAncestorWasSuccessful.

@Test
void resultOfTestIdentifierWithoutReportedEventsIsEmptyWhenAncestorWasSuccessful() {
    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());
    reportData.markFinished(testPlan.getTestIdentifier("[engine:engine]"), successful());
    Optional<TestExecutionResult> result = reportData.getResult(testPlan.getTestIdentifier("[child:test]"));
    assertThat(result).isEmpty();
}
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 10 with TestDescriptorStub

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

the class XmlReportDataTests method resultOfTestIdentifierWithoutAnyReportedEventsIsEmpty.

@Test
void resultOfTestIdentifierWithoutAnyReportedEventsIsEmpty() {
    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());
    Optional<TestExecutionResult> result = reportData.getResult(testPlan.getTestIdentifier("[child:test]"));
    assertThat(result).isEmpty();
}
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)

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