Skip to content

Commit

Permalink
Add timestamp and hostname to testsuite xml (#294)
Browse files Browse the repository at this point in the history
Fixed #293 

Per https://windyroad.com.au/dl/Open%20Source/JUnit.xsd timestamp and
hostname are required attributes on the testsuite tag.
  • Loading branch information
brian-mcnamara authored Aug 8, 2024
1 parent a78287a commit ca23db3
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static com.github.bazel_contrib.contrib_rules_jvm.junit5.SafeXml.escapeIllegalCharacters;
import static com.github.bazel_contrib.contrib_rules_jvm.junit5.SafeXml.writeTextElement;

import java.net.InetAddress;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
Expand All @@ -21,6 +23,8 @@ public void toXml(XMLStreamWriter xml, TestData suite, Collection<TestData> test
xml.writeStartElement("testsuite");

xml.writeAttribute("name", escapeIllegalCharacters(suite.getId().getLegacyReportingName()));
xml.writeAttribute("timestamp", DateTimeFormatter.ISO_INSTANT.format(suite.getStarted()));
xml.writeAttribute("hostname", getHostname());
xml.writeAttribute("tests", String.valueOf(tests.size()));

int errors = 0;
Expand Down Expand Up @@ -67,4 +71,12 @@ public void toXml(XMLStreamWriter xml, TestData suite, Collection<TestData> test

xml.writeEndElement();
}

private String getHostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
return "localhost";
}
}
}

0 comments on commit ca23db3

Please sign in to comment.