use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class DefaultLauncherTests method testPlanThrowsExceptionWhenModified.
@Test
@SuppressWarnings("deprecation")
void testPlanThrowsExceptionWhenModified() {
TestEngine engine = new TestEngineSpy();
var launcher = createLauncher(engine);
var testPlan = launcher.discover(request().build());
var engineIdentifier = getOnlyElement(testPlan.getRoots());
var engineUniqueId = UniqueId.parse(engineIdentifier.getUniqueId());
assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1);
var addedIdentifier = TestIdentifier.from(new TestDescriptorStub(engineUniqueId.append("test", "test2"), "test2"));
var exception = assertThrows(JUnitException.class, () -> testPlan.add(addedIdentifier));
assertThat(exception).hasMessage("Unsupported attempt to modify the TestPlan was detected. " + "Please contact your IDE/tool vendor and request a fix or downgrade to JUnit 5.7.x (see https://github.com/junit-team/junit5/issues/1732 for details).");
assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1).doesNotContain(addedIdentifier);
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class XmlReportWriterTests method writesValidXmlEvenIfExceptionMessageContainsCData.
@Test
void writesValidXmlEvenIfExceptionMessageContainsCData() throws Exception {
var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
var assertionError = new AssertionError("<foo><![CDATA[bar]]></foo>");
reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
var testsuite = writeXmlReport(testPlan, reportData);
assertValidAccordingToJenkinsSchema(testsuite.document());
assertThat(testsuite.find("failure").attr("message")).isEqualTo("<foo><![CDATA[bar]]></foo>");
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class XmlReportWriterTests method writesEmptySkippedElementForSkippedTestWithoutReason.
@Test
void writesEmptySkippedElementForSkippedTestWithoutReason() throws Exception {
var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "skippedTest"));
var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
reportData.markSkipped(testPlan.getTestIdentifier(uniqueId.toString()), null);
var testsuite = writeXmlReport(testPlan, reportData);
assertValidAccordingToJenkinsSchema(testsuite.document());
var testcase = testsuite.child("testcase");
assertThat(testcase.attr("name")).isEqualTo("skippedTest");
var skipped = testcase.child("skipped");
assertThat(skipped.size()).isEqualTo(1);
assertThat(skipped.children()).isEmpty();
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class XmlReportWriterTests method escapesInvalidCharactersInSystemPropertiesAndExceptionMessages.
@Test
void escapesInvalidCharactersInSystemPropertiesAndExceptionMessages() throws Exception {
var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
var assertionError = new AssertionError("expected: <A> but was: <B\0>");
reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
System.setProperty("foo.bar", "\1");
Match testsuite;
try {
testsuite = writeXmlReport(testPlan, reportData);
} finally {
System.getProperties().remove("foo.bar");
}
assertValidAccordingToJenkinsSchema(testsuite.document());
//
assertThat(testsuite.find("property").matchAttr("name", "foo\\.bar").attr("value")).isEqualTo("");
var failure = testsuite.find("failure");
//
assertThat(failure.attr("message")).isEqualTo("expected: <A> but was: <B�>");
//
assertThat(failure.text()).contains("AssertionError: expected: <A> but was: <B�>");
}
use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.
the class XmlReportWriterTests method doesNotReopenCDataWithinCDataContent.
@Test
void doesNotReopenCDataWithinCDataContent() throws Exception {
var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
var assertionError = new AssertionError("<foo><![CDATA[bar]]></foo>");
reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
Writer assertingWriter = new StringWriter() {
@SuppressWarnings("NullableProblems")
@Override
public void write(char[] buffer, int off, int len) {
assertThat(new String(buffer, off, len)).doesNotContain("]]><![CDATA[");
}
};
writeXmlReport(testPlan, reportData, assertingWriter);
}
Aggregations