Skip to content

Commit

Permalink
Merge pull request #29 from dailymotion/skip_test
Browse files Browse the repository at this point in the history
Implemented a skip test function to mark tests as skipped.
  • Loading branch information
ubermensch01 committed Mar 17, 2020
2 parents e00c8c6 + f4c70c9 commit d4de48c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
11 changes: 10 additions & 1 deletion example/example_skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import (
"testing"
)

func TestSkip(t *testing.T) {
func TestSkipStep(t *testing.T) {
allure.Test(t,
allure.Description("Skip test"),
allure.Action(func() {
allure.SkipStep(allure.Description("Skip"), allure.Action(func() {}), allure.Reason("reason"))
}))
}

func TestSkipTest(t *testing.T) {
allure.SkipTest(t,
allure.Reason("Skipping the test"),
allure.Description("Skip test"),
allure.Action(func() {
allure.SkipStep(allure.Description("Skip"), allure.Action(func() {}), allure.Reason("reason"))
}))
}
2 changes: 1 addition & 1 deletion result.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type result struct {
func (r *result) addReason(reason string) {
testStatusDetails := r.StatusDetails
if testStatusDetails == nil {
testStatusDetails = &statusDetails{}
r.StatusDetails = &statusDetails{}
}
r.StatusDetails.Message = reason
}
Expand Down
38 changes: 38 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,44 @@ type testLabels struct {
Language string
}

func SkipTest(t *testing.T, testOptions ...Option) {
var r *result
r = newResult()
r.UUID = generateUUID()
r.Start = getTimestampMs()
r.Name = strings.Join(camelcase.Split(t.Name())[1:], " ")
r.Description = t.Name()
r.setDefaultLabels(t)
r.Steps = make([]stepObject, 0)
for _, option := range testOptions {
option(r)
}

getCurrentTestPhaseObject(t).Test = r
r.Stop = getTimestampMs()
r.Stage = "finished"
r.Status = skipped
err := r.writeResultsFile()
if err != nil {
log.Println("Failed to write content of result to json file", err)
}
setups := getCurrentTestPhaseObject(t).Befores
for _, setup := range setups {
setup.Children = append(setup.Children, r.UUID)
err := setup.writeResultsFile()
if err != nil {
log.Println("Failed to write content of result to json file", err)
}
}
defer func() {
if r.StatusDetails != nil {
t.Skip(r.StatusDetails.Message)
} else {
t.Skip()
}
}()
}

//Test execute the test and creates an Allure result used by Allure reports
func Test(t *testing.T, testOptions ...Option) {
var r *result
Expand Down

0 comments on commit d4de48c

Please sign in to comment.