Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-abalik committed Jun 24, 2024
1 parent 67e0746 commit cfb8828
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,38 @@ public void ensureOutputsAreProperlyEscaped() {
assertEquals("[31mAlso bad![0m", text);
}

@Test
public void ensureTestCaseNamesAreProperlyEscaped() {
var testDescriptor = new StubbedTestDescriptor(createId("Weird\bname"));
var identifier = TestIdentifier.from(testDescriptor);

var testCaseData = new TestData(identifier);
testCaseData.mark(TestExecutionResult.successful());

Document xml = generateTestXml(Mockito.mock(TestPlan.class), testCaseData);

Node item = xml.getElementsByTagName("testcase").item(0);
String testName = item.getAttributes().getNamedItem("name").getNodeValue();

assertEquals("[engine:mocked]/[class:ExampleTest]/[method:Weirdname", testName);
}

@Test
public void ensureTestSuiteNamesAreProperlyEscaped() {
var testDescriptor = new StubbedTestDescriptor(createId("Weird\bname"));
var identifier = TestIdentifier.from(testDescriptor);

var testSuiteData = new TestData(identifier);
testSuiteData.mark(TestExecutionResult.successful());

Document xml = generateTestXml(Mockito.mock(TestPlan.class), testSuiteData, List.of());

Node item = xml.getElementsByTagName("testsuite").item(0);
String testName = item.getAttributes().getNamedItem("name").getNodeValue();

assertEquals("[engine:mocked]/[class:ExampleTest]/[method:Weirdname()]", testName);
}

private Document generateTestXml(TestPlan testPlan, TestData testCase) {
return generateDocument(xml -> new TestCaseXmlRenderer(testPlan).toXml(xml, testCase));
}
Expand Down

0 comments on commit cfb8828

Please sign in to comment.