From 7565a32d2124ba7468ac07d05a7a0badfe305a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Wed, 26 Feb 2020 17:24:04 -0300 Subject: [PATCH] Fixed an issue with missing decimals in JUnit --- fmt_junit.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fmt_junit.go b/fmt_junit.go index fc43fe9..22f6772 100644 --- a/fmt_junit.go +++ b/fmt_junit.go @@ -6,6 +6,7 @@ import ( "io" "os" "sort" + "strconv" "sync" "time" @@ -119,11 +120,15 @@ func (f *junitFormatter) Copy(cf ConcurrentFormatter) { } } +func junitTimeDuration(from, to time.Time) string { + return strconv.FormatFloat(to.Sub(from).Seconds(), 'f', -1, 64) +} + func buildJUNITPackageSuite(suiteName string, startedAt time.Time, features []*feature) junitPackageSuite { suite := junitPackageSuite{ Name: suiteName, TestSuites: make([]*junitTestSuite, len(features)), - Time: fmt.Sprintf("%.f", timeNowFunc().Sub(startedAt).Seconds()), + Time: junitTimeDuration(startedAt, timeNowFunc()), } sort.Sort(sortByName(features)) @@ -131,14 +136,15 @@ func buildJUNITPackageSuite(suiteName string, startedAt time.Time, features []*f for idx, feat := range features { ts := junitTestSuite{ Name: feat.Name, - Time: fmt.Sprintf("%.f", feat.finishedAt().Sub(feat.startedAt()).Seconds()), + Time: junitTimeDuration(feat.startedAt(), feat.finishedAt()), TestCases: make([]*junitTestCase, len(feat.Scenarios)), } for idx, scenario := range feat.Scenarios { - tc := junitTestCase{} - tc.Name = scenario.Name - tc.Time = fmt.Sprintf("%.f", scenario.finishedAt().Sub(scenario.startedAt()).Seconds()) + tc := junitTestCase{ + Name: scenario.Name, + Time: junitTimeDuration(scenario.startedAt(), scenario.finishedAt()), + } ts.Tests++ suite.Tests++