Skip to content

Commit

Permalink
junitrunner: Report suppressed and ignored tests as skipped.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#6688
(after java tools release)

Closes bazelbuild#13717.

PiperOrigin-RevId: 385953369
  • Loading branch information
benjaminp authored and copybara-github committed Jul 21, 2021
1 parent 03bd0eb commit 45092bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 45092bb

Please sign in to comment.