use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class XmlReportWriterTests method writesEmptyErrorElementForFailedTestWithoutCause.
@Test
void writesEmptyErrorElementForFailedTestWithoutCause() throws Exception {
engineDescriptor = new EngineDescriptor(UniqueId.forEngine("myEngineId"), "Fancy Engine") {
@Override
public String getLegacyReportingName() {
return "myEngine";
}
};
var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "some fancy name") {
@Override
public String getLegacyReportingName() {
return "failedTest";
}
});
var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(null));
var testsuite = writeXmlReport(testPlan, reportData);
assertValidAccordingToJenkinsSchema(testsuite.document());
var testcase = testsuite.child("testcase");
assertThat(testcase.attr("name")).isEqualTo("failedTest");
assertThat(testcase.attr("classname")).isEqualTo("myEngine");
var error = testcase.child("error");
assertThat(error.size()).isEqualTo(1);
assertThat(error.children()).isEmpty();
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class LegacyXmlReportGeneratingListenerTests method writesReportEntriesToSystemOutElement.
@Test
void writesReportEntriesToSystemOutElement() throws Exception {
var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
var testPlan = TestPlan.from(Set.of(engineDescriptor), mock(ConfigurationParameters.class));
var out = new StringWriter();
var listener = new LegacyXmlReportGeneratingListener(tempDirectory, new PrintWriter(out));
listener.testPlanExecutionStarted(testPlan);
var 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());
var testsuite = readValidXmlFile(tempDirectory.resolve("TEST-engine.xml"));
//
assertThat(String.join("\n", testsuite.child("testcase").children("system-out").texts())).containsSubsequence("Report Entry #1 (timestamp: " + Year.now(), "- foo: bar\n", "Report Entry #2 (timestamp: " + Year.now(), "- bar: baz\n", "- qux: foo\n");
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class XmlReportDataTests method resultsOfTestIdentifierWithoutReportedEventsContainsOnlyFailureOfAncestor.
@Test
void resultsOfTestIdentifierWithoutReportedEventsContainsOnlyFailureOfAncestor() {
var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
var failureOfAncestor = failed(new RuntimeException("failed!"));
reportData.markFinished(testPlan.getTestIdentifier("[engine:engine]"), failureOfAncestor);
var results = reportData.getResults(testPlan.getTestIdentifier("[child:test]"));
assertThat(results).containsExactly(failureOfAncestor);
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class SummaryGenerationTests method reportingCorrectFailures.
@Test
void reportingCorrectFailures() {
var iaeCausedBy = new IllegalArgumentException("Illegal Argument Exception");
var failedException = new RuntimeException("Runtime Exception", iaeCausedBy);
var npeSuppressed = new NullPointerException("Null Pointer Exception");
failedException.addSuppressed(npeSuppressed);
var testDescriptor = new TestDescriptorStub(UniqueId.root("root", "2"), "failingTest") {
@Override
public Optional<TestSource> getSource() {
return Optional.of(ClassSource.from(Object.class));
}
};
var failed = TestIdentifier.from(testDescriptor);
var aborted = TestIdentifier.from(new TestDescriptorStub(UniqueId.root("root", "3"), "abortedTest"));
listener.testPlanExecutionStarted(testPlan);
listener.executionStarted(failed);
listener.executionFinished(failed, TestExecutionResult.failed(failedException));
listener.executionStarted(aborted);
listener.executionFinished(aborted, TestExecutionResult.aborted(new RuntimeException("aborted")));
listener.testPlanExecutionFinished(testPlan);
// An aborted test is not a failure
assertEquals(1, listener.getSummary().getTestsFailedCount());
var failuresString = failuresAsString();
assertAll(//
"failures", //
() -> assertTrue(failuresString.contains("Failures (1)"), "test failures"), //
() -> assertTrue(failuresString.contains(Object.class.getName()), "source"), //
() -> assertTrue(failuresString.contains("failingTest"), "display name"), //
() -> assertTrue(failuresString.contains("=> " + failedException), "main exception"), //
() -> assertTrue(failuresString.contains("Caused by: " + iaeCausedBy), "Caused by exception"), //
() -> assertTrue(failuresString.contains("Suppressed: " + npeSuppressed), "Suppressed exception"));
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class SummaryGenerationTests method createContainerIdentifier.
private TestIdentifier createContainerIdentifier(String uniqueId) {
var identifier = TestIdentifier.from(new TestDescriptorStub(UniqueId.root("container", uniqueId), uniqueId) {
@Override
public Type getType() {
return Type.CONTAINER;
}
});
testPlan.addInternal(identifier);
return identifier;
}
Aggregations