Skip to content

Commit

Permalink
JUnit report has time reported as seconds instead of millis. Closes c…
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jun 15, 2012
1 parent cf39239 commit ff1a36b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
19 changes: 15 additions & 4 deletions core/src/main/java/cucumber/formatter/JUnitFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,6 +165,12 @@ public void syntaxError(String state, String event, List<String> 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;
}
Expand All @@ -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;
Expand Down

0 comments on commit ff1a36b

Please sign in to comment.