From bf4f4babfd23a4f9dcfe5f6358c5793c38b20ebf Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Tue, 12 Aug 2025 17:27:32 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 2 ++ .../junitxmlformatter/XmlReportWriter.java | 7 ++--- ...essagesToJunitXmlWriterAcceptanceTest.java | 17 +---------- .../MessagesToJunitXmlWriterTest.java | 4 +-- ...-3.0.xsd => surefire-test-report-3.0.2.xsd | 28 ++++++++----------- 5 files changed, 19 insertions(+), 39 deletions(-) rename surefire-test-report-3.0.xsd => surefire-test-report-3.0.2.xsd (91%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4094610..5406433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- [Java] Format time as xs:float ([#83](https://github.com/cucumber/junit-xml-formatter/pull/83)) ## [0.8.0] - 2025-07-07 ### Added diff --git a/java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java b/java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java index aa763d3..040b27d 100644 --- a/java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java +++ b/java/src/main/java/io/cucumber/junitxmlformatter/XmlReportWriter.java @@ -9,9 +9,7 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import java.io.Writer; -import java.text.NumberFormat; import java.util.EnumSet; -import java.util.Locale; import java.util.Map; import java.util.Optional; @@ -19,7 +17,6 @@ import static io.cucumber.messages.types.TestStepResultStatus.SKIPPED; class XmlReportWriter { - private final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); private final XmlReportData data; XmlReportWriter(XmlReportData data) { @@ -51,7 +48,7 @@ private void writeTestsuite(EscapingXmlStreamWriter writer) throws XMLStreamExce private void writeSuiteAttributes(EscapingXmlStreamWriter writer) throws XMLStreamException { writer.writeAttribute("name", "Cucumber"); - writer.writeAttribute("time", numberFormat.format(data.getSuiteDurationInSeconds())); + writer.writeAttribute("time", String.valueOf(data.getSuiteDurationInSeconds())); Map counts = data.getTestCaseStatusCounts(); @@ -90,7 +87,7 @@ private void writeTestcase(EscapingXmlStreamWriter writer, TestCaseStarted testC private void writeTestCaseAttributes(EscapingXmlStreamWriter writer, TestCaseStarted testCaseStarted) throws XMLStreamException { writer.writeAttribute("classname", data.getFeatureName(testCaseStarted)); writer.writeAttribute("name", data.getPickleName(testCaseStarted)); - writer.writeAttribute("time", numberFormat.format(data.getDurationInSeconds(testCaseStarted))); + writer.writeAttribute("time", String.valueOf(data.getDurationInSeconds(testCaseStarted))); } private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStarted testCaseStarted) throws XMLStreamException { diff --git a/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterAcceptanceTest.java b/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterAcceptanceTest.java index 4866537..b0b1493 100644 --- a/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterAcceptanceTest.java +++ b/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterAcceptanceTest.java @@ -77,7 +77,7 @@ void validateAgainstJenkins(TestCase testCase) throws IOException { void validateAgainstSurefire(TestCase testCase) throws IOException { ByteArrayOutputStream bytes = writeJunitXmlReport(testCase, new ByteArrayOutputStream()); Source actual = Input.fromByteArray(bytes.toByteArray()).build(); - Source surefireSchema = Input.fromPath(Paths.get("../surefire-test-report-3.0.xsd")).build(); + Source surefireSchema = Input.fromPath(Paths.get("../surefire-test-report-3.0.2.xsd")).build(); JAXPValidator validator = new JAXPValidator(Languages.W3C_XML_SCHEMA_NS_URI); validator.setSchemaSource(surefireSchema); @@ -88,22 +88,7 @@ void validateAgainstSurefire(TestCase testCase) throws IOException { * We add the timestamp attribute to all reports. */ expectedProblems.add("cvc-complex-type.3.2.2: Attribute 'timestamp' is not allowed to appear in element 'testsuite'."); - /* - This report tries to be compatible with the Jenkins XSD. The Surefire - XSD is a bit stricter and generally assumes tests fail with an - exception. While this is true for Cucumber-JVM, this isn't true for - all Cucumber implementations. - - E.g. in Cucumber-JVM a scenario would report it is pending by throwing - a PendingException. However, in Javascript this would be done by - returning the string "pending". - Since the Surefire XSD is also relatively popular we do check it and - exclude the cases that don't pass selectively. - */ - if (testCasesWithMissingException.contains(testCase.name)) { - expectedProblems.add("cvc-complex-type.4: Attribute 'type' must appear on element 'failure'."); - } Iterable problems = validationResult.getProblems(); Assertions.assertThat(problems).extracting(ValidationProblem::getMessage).containsAll(expectedProblems); } diff --git a/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterTest.java b/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterTest.java index 15a7906..cb7f1dc 100644 --- a/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterTest.java +++ b/java/src/test/java/io/cucumber/junitxmlformatter/MessagesToJunitXmlWriterTest.java @@ -28,7 +28,7 @@ void it_writes_two_messages_to_xml() throws IOException { assertThat(html).isEqualTo("" + "\n" + - "\n" + + "\n" + "\n" ); } @@ -38,7 +38,7 @@ void it_writes_no_message_to_xml() throws IOException { String html = renderAsJunitXml(); assertThat(html).isEqualTo("" + "\n" + - "\n" + + "\n" + "\n" ); } diff --git a/surefire-test-report-3.0.xsd b/surefire-test-report-3.0.2.xsd similarity index 91% rename from surefire-test-report-3.0.xsd rename to surefire-test-report-3.0.2.xsd index 69d9c93..7903360 100644 --- a/surefire-test-report-3.0.xsd +++ b/surefire-test-report-3.0.2.xsd @@ -1,6 +1,6 @@ - - - - - - + - + @@ -50,7 +45,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + @@ -63,7 +58,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + @@ -74,7 +69,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + @@ -91,7 +86,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + @@ -104,7 +99,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + @@ -115,7 +110,7 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + @@ -124,12 +119,13 @@ Via: https://maven.apache.org/surefire/maven-surefire-plugin/ - + + - +