Skip to content

Commit

Permalink
Merge pull request #308 from cucumber/bugfix/junit-testsuite-time
Browse files Browse the repository at this point in the history
Fixed an issue with calculating time for junit testsuite
  • Loading branch information
lonnblad authored Jun 13, 2020
2 parents 849e8e4 + e61d355 commit a03a1b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
7 changes: 0 additions & 7 deletions feature.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package godog

import (
"time"

"github.com/cucumber/messages-go/v10"
)

type feature struct {
*messages.GherkinDocument
pickles []*messages.Pickle

time time.Time
content []byte
order int
}
Expand Down Expand Up @@ -90,7 +87,3 @@ func (f feature) findStep(astStepID string) *messages.GherkinDocument_Feature_St

return nil
}

func (f feature) startedAt() time.Time {
return f.time
}
28 changes: 12 additions & 16 deletions fmt_junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,8 @@ func (f *junitFormatter) buildJUNITPackageSuite() junitPackageSuite {
pickles := f.storage.mustGetPickles(feature.Uri)
sort.Sort(sortPicklesByID(pickles))

var finishedAt = feature.startedAt()

if len(pickles) > 0 {
lastPickle := pickles[len(pickles)-1]

if len(lastPickle.Steps) > 0 {
lastStep := lastPickle.Steps[len(lastPickle.Steps)-1]
lastPickleStepResult := f.storage.mustGetPickleStepResult(lastStep.Id)
finishedAt = lastPickleStepResult.finishedAt
}
}

ts := junitTestSuite{
Name: feature.Feature.Name,
Time: junitTimeDuration(feature.startedAt(), finishedAt),
TestCases: make([]*junitTestCase, len(pickles)),
}

Expand All @@ -90,21 +77,28 @@ func (f *junitFormatter) buildJUNITPackageSuite() junitPackageSuite {
testcaseNames[pickle.Name] = testcaseNames[pickle.Name] + 1
}

firstPickleStartedAt := f.startedAt
lastPickleFinishedAt := f.startedAt

var outlineNo = make(map[string]int)
for idx, pickle := range pickles {
tc := junitTestCase{}

pickleResult := f.storage.mustGetPickleResult(pickle.Id)

var finishedAt = pickleResult.StartedAt
if idx == 0 {
firstPickleStartedAt = pickleResult.StartedAt
}

lastPickleFinishedAt = pickleResult.StartedAt

if len(pickle.Steps) > 0 {
lastStep := pickle.Steps[len(pickle.Steps)-1]
lastPickleStepResult := f.storage.mustGetPickleStepResult(lastStep.Id)
finishedAt = lastPickleStepResult.finishedAt
lastPickleFinishedAt = lastPickleStepResult.finishedAt
}

tc.Time = junitTimeDuration(pickleResult.StartedAt, finishedAt)
tc.Time = junitTimeDuration(pickleResult.StartedAt, lastPickleFinishedAt)

tc.Name = pickle.Name
if testcaseNames[tc.Name] > 1 {
Expand Down Expand Up @@ -159,6 +153,8 @@ func (f *junitFormatter) buildJUNITPackageSuite() junitPackageSuite {
ts.TestCases[idx] = &tc
}

ts.Time = junitTimeDuration(firstPickleStartedAt, lastPickleFinishedAt)

suite.TestSuites[idx] = &ts
}

Expand Down

0 comments on commit a03a1b8

Please sign in to comment.