Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

junitrunner: Report suppressed and ignored tests as skipped. #13717

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public final class AntXmlResultWriter implements XmlResultWriter {
private static final String JUNIT_ELEMENT_PROPERTY = "property";
private static final String JUNIT_ELEMENT_TESTCASE = "testcase";
private static final String JUNIT_ELEMENT_FAILURE = "failure";
private static final String JUNIT_ELEMENT_SKIPPED = "skipped";

private static final String JUNIT_ATTR_TESTSUITE_ERRORS = "errors";
private static final String JUNIT_ATTR_TESTSUITE_FAILURES = "failures";
Expand Down Expand Up @@ -113,7 +114,7 @@ private void writeTestSuiteProperties(XmlWriter writer, TestResult result) throw
private void writeTestCases(XmlWriter writer, TestResult result,
Iterable<Throwable> parentFailures) throws IOException {
for (TestResult child : result.getChildResults()) {
if (child.getStatus() == TestResult.Status.FILTERED) {
if (child.getStatus().equals(TestResult.Status.FILTERED)) {
continue;
}
if (child.getChildResults().isEmpty()) {
Expand Down Expand Up @@ -175,6 +176,12 @@ private void writeTestCase(XmlWriter writer, TestResult result,
writeThrowableToXmlWriter(writer, failure);
}

if (result.getStatus().equals(TestResult.Status.SKIPPED)
|| result.getStatus().equals(TestResult.Status.SUPPRESSED)) {
writer.startElement(JUNIT_ELEMENT_SKIPPED);
writer.endElement();
}

writer.endElement();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.runners.JUnit4;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

@RunWith(JUnit4.class)
Expand Down Expand Up @@ -115,6 +116,27 @@ public void testWallTimeAndMonotonicTimestamp() throws Exception {
.isEqualTo(startTime);
}

@Test
public void testSkippedOrSuppressedReportedAsSkipped() throws Exception {
TestSuiteNode parent = createTestSuite();
TestCaseNode skipped = createTestCase(parent);
skipped.started(testInstant(Instant.ofEpochMilli(1)));
skipped.testSkipped(testInstant(Instant.ofEpochMilli(2)));
TestCaseNode suppressed = createTestCase(parent);
suppressed.testSuppressed(testInstant(Instant.ofEpochMilli(4)));

resultWriter.writeTestSuites(writer, root.getResult());

Document document = parseXml(stringWriter.toString());
NodeList caseElems = document.getElementsByTagName("testcase");
assertThat(caseElems.getLength()).isEqualTo(2);
for (int i = 0; i < 2; i++) {
Element caseElem = (Element) caseElems.item(i);
NodeList skippedElems = caseElem.getElementsByTagName("skipped");
assertThat(skippedElems.getLength()).isEqualTo(1);
}
}

private void runToCompletion(TestCaseNode test) {
test.started(testInstant(Instant.ofEpochMilli(1)));
test.finished(testInstant(Instant.ofEpochMilli(2)));
Expand Down