Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark junit test cases as skipped if no pickle step results available #597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 54 additions & 15 deletions internal/formatters/fmt_junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"time"

"github.com/cucumber/godog/formatters"
"github.com/cucumber/godog/internal/models"
"github.com/cucumber/godog/internal/utils"
)

Expand Down Expand Up @@ -47,6 +48,40 @@
return strconv.FormatFloat(to.Sub(from).Seconds(), 'f', -1, 64)
}

// getPickleResult deals with the fact that if there's no result due to 'StopOnFirstFailure' being
// set, MustGetPickleResult panics.
func (f *JUnit) getPickleResult(pickleID string) (res *models.PickleResult) {
defer func() {
if r := recover(); r != nil {
res = nil

Check warning on line 56 in internal/formatters/fmt_junit.go

View check run for this annotation

Codecov / codecov/patch

internal/formatters/fmt_junit.go#L56

Added line #L56 was not covered by tests
}
}()
pr := f.Storage.MustGetPickleResult(pickleID)
res = &pr
return
}

func (f *JUnit) getPickleStepResult(stepID string) (res *models.PickleStepResult) {
defer func() {
if r := recover(); r != nil {
res = nil

Check warning on line 67 in internal/formatters/fmt_junit.go

View check run for this annotation

Codecov / codecov/patch

internal/formatters/fmt_junit.go#L67

Added line #L67 was not covered by tests
}
}()
psr := f.Storage.MustGetPickleStepResult(stepID)
res = &psr
return
}

func (f *JUnit) getPickleStepResultsByPickleID(pickleID string) (res []models.PickleStepResult) {
defer func() {
if r := recover(); r != nil {
res = nil

Check warning on line 78 in internal/formatters/fmt_junit.go

View check run for this annotation

Codecov / codecov/patch

internal/formatters/fmt_junit.go#L78

Added line #L78 was not covered by tests
}
}()
res = f.Storage.MustGetPickleStepResultsByPickleID(pickleID)
return
}

func (f *JUnit) buildJUNITPackageSuite() JunitPackageSuite {
features := f.Storage.MustGetFeatures()
sort.Sort(sortFeaturesByName(features))
Expand Down Expand Up @@ -79,33 +114,37 @@
var outlineNo = make(map[string]int)
for idx, pickle := range pickles {
tc := junitTestCase{}

pickleResult := f.Storage.MustGetPickleResult(pickle.Id)

if idx == 0 {
firstPickleStartedAt = pickleResult.StartedAt
tc.Name = pickle.Name
if testcaseNames[tc.Name] > 1 {
outlineNo[tc.Name] = outlineNo[tc.Name] + 1
tc.Name += fmt.Sprintf(" #%d", outlineNo[tc.Name])
}

lastPickleFinishedAt = pickleResult.StartedAt
pickleResult := f.getPickleResult(pickle.Id)
if pickleResult == nil {
tc.Status = skipped.String()

Check warning on line 125 in internal/formatters/fmt_junit.go

View check run for this annotation

Codecov / codecov/patch

internal/formatters/fmt_junit.go#L125

Added line #L125 was not covered by tests
} else {
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)
lastPickleFinishedAt = lastPickleStepResult.FinishedAt
if lastPickleStepResult := f.getPickleStepResult(lastStep.Id); lastPickleStepResult != nil {
lastPickleFinishedAt = lastPickleStepResult.FinishedAt
}
}

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

tc.Name = pickle.Name
if testcaseNames[tc.Name] > 1 {
outlineNo[tc.Name] = outlineNo[tc.Name] + 1
tc.Name += fmt.Sprintf(" #%d", outlineNo[tc.Name])
if pickleResult != nil {
tc.Time = junitTimeDuration(pickleResult.StartedAt, lastPickleFinishedAt)
}

ts.Tests++
suite.Tests++

pickleStepResults := f.Storage.MustGetPickleStepResultsByPickleID(pickle.Id)
pickleStepResults := f.getPickleStepResultsByPickleID(pickle.Id)
for _, stepResult := range pickleStepResults {
pickleStep := f.Storage.MustGetPickleStep(stepResult.PickleStepID)

Expand Down
Loading