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
}
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
}
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);
}
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();
}
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();
}
Aggregations