Skip to content

Commit f4e6755

Browse files
committed
java: Format time as xs:float
Surefire changed their xsd to use xs:float instead of a number formatted in the US locale. Formatting this is the default representation in Java. Fixes: #82 1. https://www.datypic.com/sc/xsd/t-xsd_float.html
1 parent e2bb2c1 commit f4e6755

File tree

4 files changed

+17
-37
lines changed

4 files changed

+17
-37
lines changed

java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static io.cucumber.messages.types.TestStepResultStatus.SKIPPED;
2020

2121
class XmlReportWriter {
22-
private final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
2322
private final XmlReportData data;
2423

2524
XmlReportWriter(XmlReportData data) {
@@ -51,7 +50,7 @@ private void writeTestsuite(EscapingXmlStreamWriter writer) throws XMLStreamExce
5150

5251
private void writeSuiteAttributes(EscapingXmlStreamWriter writer) throws XMLStreamException {
5352
writer.writeAttribute("name", "Cucumber");
54-
writer.writeAttribute("time", numberFormat.format(data.getSuiteDurationInSeconds()));
53+
writer.writeAttribute("time", String.valueOf(data.getSuiteDurationInSeconds()));
5554

5655
Map<TestStepResultStatus, Long> counts = data.getTestCaseStatusCounts();
5756

@@ -90,7 +89,7 @@ private void writeTestcase(EscapingXmlStreamWriter writer, TestCaseStarted testC
9089
private void writeTestCaseAttributes(EscapingXmlStreamWriter writer, TestCaseStarted testCaseStarted) throws XMLStreamException {
9190
writer.writeAttribute("classname", data.getFeatureName(testCaseStarted));
9291
writer.writeAttribute("name", data.getPickleName(testCaseStarted));
93-
writer.writeAttribute("time", numberFormat.format(data.getDurationInSeconds(testCaseStarted)));
92+
writer.writeAttribute("time", String.valueOf(data.getDurationInSeconds(testCaseStarted)));
9493
}
9594

9695
private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStarted testCaseStarted) throws XMLStreamException {

java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterAcceptanceTest.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void validateAgainstJenkins(TestCase testCase) throws IOException {
7777
void validateAgainstSurefire(TestCase testCase) throws IOException {
7878
ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, new ByteArrayOutputStream());
7979
Source actual = Input.fromByteArray(bytes.toByteArray()).build();
80-
Source surefireSchema = Input.fromPath(Paths.get("../surefire-test-report-3.0.xsd")).build();
80+
Source surefireSchema = Input.fromPath(Paths.get("../surefire-test-report-3.0.2.xsd")).build();
8181

8282
JAXPValidator validator = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI);
8383
validator.setSchemaSource(surefireSchema);
@@ -88,22 +88,7 @@ void validateAgainstSurefire(TestCase testCase) throws IOException {
8888
* We add the timestamp attribute to all reports.
8989
*/
9090
expectedProblems.add("cvc-complex-type.3.2.2: Attribute 'timestamp' is not allowed to appear in element 'testsuite'.");
91-
/*
92-
This report tries to be compatible with the Jenkins XSD. The Surefire
93-
XSD is a bit stricter and generally assumes tests fail with an
94-
exception. While this is true for Cucumber-JVM, this isn't true for
95-
all Cucumber implementations.
96-
97-
E.g. in Cucumber-JVM a scenario would report it is pending by throwing
98-
a PendingException. However, in Javascript this would be done by
99-
returning the string "pending".
10091

101-
Since the Surefire XSD is also relatively popular we do check it and
102-
exclude the cases that don't pass selectively.
103-
*/
104-
if (testCasesWithMissingException.contains(testCase.name)) {
105-
expectedProblems.add("cvc-complex-type.4: Attribute 'type' must appear on element 'failure'.");
106-
}
10792
Iterable<ValidationProblem> problems = validationResult.getProblems();
10893
Assertions.assertThat(problems).extracting(ValidationProblem::getMessage).containsAll(expectedProblems);
10994
}

java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void it_writes_two_messages_to_xml() throws IOException {
2828

2929
assertThat(html).isEqualTo("" +
3030
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
31-
"<testsuite name=\"Cucumber\" time=\"20\" tests=\"0\" skipped=\"0\" failures=\"0\" errors=\"0\" timestamp=\"1970-01-01T00:00:10Z\">\n" +
31+
"<testsuite name=\"Cucumber\" time=\"20.0\" tests=\"0\" skipped=\"0\" failures=\"0\" errors=\"0\" timestamp=\"1970-01-01T00:00:10Z\">\n" +
3232
"</testsuite>\n"
3333
);
3434
}
@@ -38,7 +38,7 @@ void it_writes_no_message_to_xml() throws IOException {
3838
String html = renderAsJunitXml();
3939
assertThat(html).isEqualTo("" +
4040
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
41-
"<testsuite name=\"Cucumber\" time=\"0\" tests=\"0\" skipped=\"0\" failures=\"0\" errors=\"0\">\n" +
41+
"<testsuite name=\"Cucumber\" time=\"0.0\" tests=\"0\" skipped=\"0\" failures=\"0\" errors=\"0\">\n" +
4242
"</testsuite>\n"
4343
);
4444
}

surefire-test-report-3.0.xsd renamed to surefire-test-report-3.0.2.xsd

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
From: https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd
3+
From: https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd
44
Via: https://maven.apache.org/surefire/maven-surefire-plugin/
55
-->
66
<!--
@@ -21,16 +21,11 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
2121
~ specific language governing permissions and limitations
2222
~ under the License.
2323
-->
24-
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
25-
<xs:simpleType name="SUREFIRE_TIME">
26-
<xs:restriction base="xs:string">
27-
<xs:pattern value="(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?"/>
28-
</xs:restriction>
29-
</xs:simpleType>
24+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0.2">
3025
<xs:element name="testsuite">
3126
<xs:complexType>
3227
<xs:sequence>
33-
<xs:element name="properties" minOccurs="0" maxOccurs="unbounded">
28+
<xs:element name="properties" minOccurs="0">
3429
<xs:complexType>
3530
<xs:sequence>
3631
<xs:element name="property" minOccurs="0" maxOccurs="unbounded">
@@ -50,7 +45,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
5045
<xs:simpleContent>
5146
<xs:extension base="xs:string">
5247
<xs:attribute name="message" type="xs:string"/>
53-
<xs:attribute name="type" type="xs:string" use="required"/>
48+
<xs:attribute name="type" type="xs:string"/>
5449
</xs:extension>
5550
</xs:simpleContent>
5651
</xs:complexType>
@@ -63,7 +58,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
6358
<xs:element name="system-err" type="xs:string" minOccurs="0"/>
6459
</xs:sequence>
6560
<xs:attribute name="message" type="xs:string"/>
66-
<xs:attribute name="type" type="xs:string" use="required"/>
61+
<xs:attribute name="type" type="xs:string"/>
6762
</xs:complexType>
6863
</xs:element>
6964
<xs:element name="flakyFailure" minOccurs="0" maxOccurs="unbounded">
@@ -74,7 +69,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
7469
<xs:element name="system-err" type="xs:string" minOccurs="0"/>
7570
</xs:sequence>
7671
<xs:attribute name="message" type="xs:string"/>
77-
<xs:attribute name="type" type="xs:string" use="required"/>
72+
<xs:attribute name="type" type="xs:string"/>
7873
</xs:complexType>
7974
</xs:element>
8075
<xs:element name="skipped" nillable="true" minOccurs="0" maxOccurs="1">
@@ -91,7 +86,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
9186
<xs:simpleContent>
9287
<xs:extension base="xs:string">
9388
<xs:attribute name="message" type="xs:string"/>
94-
<xs:attribute name="type" type="xs:string" use="required"/>
89+
<xs:attribute name="type" type="xs:string"/>
9590
</xs:extension>
9691
</xs:simpleContent>
9792
</xs:complexType>
@@ -104,7 +99,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
10499
<xs:element name="system-err" type="xs:string" minOccurs="0"/>
105100
</xs:sequence>
106101
<xs:attribute name="message" type="xs:string"/>
107-
<xs:attribute name="type" type="xs:string" use="required"/>
102+
<xs:attribute name="type" type="xs:string"/>
108103
</xs:complexType>
109104
</xs:element>
110105
<xs:element name="flakyError" minOccurs="0" maxOccurs="unbounded">
@@ -115,7 +110,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
115110
<xs:element name="system-err" type="xs:string" minOccurs="0"/>
116111
</xs:sequence>
117112
<xs:attribute name="message" type="xs:string"/>
118-
<xs:attribute name="type" type="xs:string" use="required"/>
113+
<xs:attribute name="type" type="xs:string"/>
119114
</xs:complexType>
120115
</xs:element>
121116
<xs:element name="system-out" type="xs:string" minOccurs="0"/>
@@ -124,12 +119,13 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/
124119
<xs:attribute name="name" type="xs:string" use="required"/>
125120
<xs:attribute name="classname" type="xs:string"/>
126121
<xs:attribute name="group" type="xs:string"/>
127-
<xs:attribute name="time" type="SUREFIRE_TIME" use="required"/>
122+
<xs:attribute name="time" type="xs:float" use="required"/>
128123
</xs:complexType>
129124
</xs:element>
130125
</xs:sequence>
126+
<xs:attribute name="version" type="xs:string"/>
131127
<xs:attribute name="name" type="xs:string" use="required"/>
132-
<xs:attribute name="time" type="SUREFIRE_TIME"/>
128+
<xs:attribute name="time" type="xs:float"/>
133129
<xs:attribute name="tests" type="xs:string" use="required"/>
134130
<xs:attribute name="errors" type="xs:string" use="required"/>
135131
<xs:attribute name="skipped" type="xs:string" use="required"/>

0 commit comments

Comments
 (0)