diff --git a/History.md b/History.md index eb327bb454..483825350e 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,6 @@ ## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.0.9...master) +* [Core/JUnit] JUnit report has time reported as seconds instead of millis. ([#347](https://github.com/cucumber/cucumber-jvm/issues/347) Aslak Hellesøy) * [Core] List legal enum values if conversion fails ([#344](https://github.com/cucumber/cucumber-jvm/issues/344) Aslak Hellesøy) * [Weld] Added workaround for [WELD-1119](https://issues.jboss.org/browse/WELD-1119) when running on single core machines. (Aslak Hellesøy) diff --git a/core/src/main/java/cucumber/formatter/JUnitFormatter.java b/core/src/main/java/cucumber/formatter/JUnitFormatter.java index 31dc997148..dbb84b316b 100644 --- a/core/src/main/java/cucumber/formatter/JUnitFormatter.java +++ b/core/src/main/java/cucumber/formatter/JUnitFormatter.java @@ -26,8 +26,11 @@ import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class JUnitFormatter implements Formatter, Reporter { private final File out; @@ -162,6 +165,12 @@ public void syntaxError(String state, String event, List legalEvents, St } private static class TestCase { + private static final DecimalFormat NUMBER_FORMAT = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); + + static { + NUMBER_FORMAT.applyPattern("0.######"); + } + private TestCase(Scenario scenario) { this.scenario = scenario; } @@ -179,12 +188,14 @@ private Element writeTo(Document doc) { Element tc = doc.createElement("testcase"); tc.setAttribute("classname", feature.getName()); tc.setAttribute("name", examples > 0 ? scenario.getName() + "_" + examples-- : scenario.getName()); - long time = 0; + long totalDurationNanos = 0; for (Result r : results) { - long durationMillis = r.getDuration() == null ? 0 : r.getDuration() / 1000000; // duration is reported in nanos - time += durationMillis; + totalDurationNanos += r.getDuration() == null ? 0 : r.getDuration(); } - tc.setAttribute("time", String.valueOf(time)); + + double totalDurationSeconds = ((double) totalDurationNanos) / 1000000000; + String time = NUMBER_FORMAT.format(totalDurationSeconds); + tc.setAttribute("time", time); StringBuilder sb = new StringBuilder(); Result skipped = null, failed = null;