Skip to content

Commit

Permalink
Correctly round suite time in junit reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Nodari authored and Andrea Nodari committed Sep 17, 2018
1 parent 46bbc26 commit 2445fc1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion reporters/junit_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (reporter *JUnitReporter) SpecDidComplete(specSummary *types.SpecSummary) {

func (reporter *JUnitReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
reporter.suite.Tests = summary.NumberOfSpecsThatWillBeRun
reporter.suite.Time = math.Trunc(summary.RunTime.Seconds() * 1000 / 1000)
reporter.suite.Time = math.Trunc(summary.RunTime.Seconds()*1000) / 1000
reporter.suite.Failures = summary.NumberOfFailedSpecs
reporter.suite.Errors = 0
file, err := os.Create(reporter.filename)
Expand Down
13 changes: 7 additions & 6 deletions reporters/junit_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var _ = Describe("JUnit Reporter", func() {
outputFile string
reporter Reporter
)
testSuiteTime := 12345 * time.Millisecond
testSuiteTime := 12456999 * time.Microsecond
reportedSuiteTime := 12.456

readOutputFile := func() reporters.JUnitTestSuite {
bytes, err := ioutil.ReadFile(outputFile)
Expand Down Expand Up @@ -80,7 +81,7 @@ var _ = Describe("JUnit Reporter", func() {
Ω(output.Name).Should(Equal("My test suite"))
Ω(output.Tests).Should(Equal(1))
Ω(output.Failures).Should(Equal(0))
Ω(output.Time).Should(Equal(12.0))
Ω(output.Time).Should(Equal(reportedSuiteTime))
Ω(output.Errors).Should(Equal(0))
Ω(output.TestCases).Should(HaveLen(1))
Ω(output.TestCases[0].Name).Should(Equal("A B C"))
Expand Down Expand Up @@ -118,7 +119,7 @@ var _ = Describe("JUnit Reporter", func() {
Ω(output.Name).Should(Equal("My test suite"))
Ω(output.Tests).Should(Equal(1))
Ω(output.Failures).Should(Equal(1))
Ω(output.Time).Should(Equal(12.0))
Ω(output.Time).Should(Equal(reportedSuiteTime))
Ω(output.Errors).Should(Equal(0))
Ω(output.TestCases[0].Name).Should(Equal("BeforeSuite"))
Ω(output.TestCases[0].Time).Should(Equal(3.0))
Expand Down Expand Up @@ -158,7 +159,7 @@ var _ = Describe("JUnit Reporter", func() {
Ω(output.Name).Should(Equal("My test suite"))
Ω(output.Tests).Should(Equal(1))
Ω(output.Failures).Should(Equal(1))
Ω(output.Time).Should(Equal(12.0))
Ω(output.Time).Should(Equal(reportedSuiteTime))
Ω(output.Errors).Should(Equal(0))
Ω(output.TestCases[0].Name).Should(Equal("AfterSuite"))
Ω(output.TestCases[0].Time).Should(Equal(3.0))
Expand Down Expand Up @@ -210,7 +211,7 @@ var _ = Describe("JUnit Reporter", func() {
Ω(output.Name).Should(Equal("My test suite"))
Ω(output.Tests).Should(Equal(1))
Ω(output.Failures).Should(Equal(1))
Ω(output.Time).Should(Equal(12.0))
Ω(output.Time).Should(Equal(reportedSuiteTime))
Ω(output.Errors).Should(Equal(0))
Ω(output.TestCases[0].Name).Should(Equal("A B C"))
Ω(output.TestCases[0].ClassName).Should(Equal("My test suite"))
Expand Down Expand Up @@ -247,7 +248,7 @@ var _ = Describe("JUnit Reporter", func() {
output := readOutputFile()
Ω(output.Tests).Should(Equal(1))
Ω(output.Failures).Should(Equal(0))
Ω(output.Time).Should(Equal(12.0))
Ω(output.Time).Should(Equal(reportedSuiteTime))
Ω(output.Errors).Should(Equal(0))
Ω(output.TestCases[0].Name).Should(Equal("A B C"))
Ω(output.TestCases[0].Skipped).ShouldNot(BeNil())
Expand Down

0 comments on commit 2445fc1

Please sign in to comment.