diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java index 2949a8a3b06295..0c7c2b77d97ea0 100644 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java @@ -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"; @@ -113,7 +114,7 @@ private void writeTestSuiteProperties(XmlWriter writer, TestResult result) throw private void writeTestCases(XmlWriter writer, TestResult result, Iterable 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()) { @@ -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(); } diff --git a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/model/AntXmlResultWriterTest.java b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/model/AntXmlResultWriterTest.java index ab88e9a09c940e..b1fb2965b93c12 100644 --- a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/model/AntXmlResultWriterTest.java +++ b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/model/AntXmlResultWriterTest.java @@ -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) @@ -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)));