forked from cucumber/godog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt_junit_test.go
170 lines (154 loc) · 3.64 KB
/
fmt_junit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package godog
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"strings"
"testing"
"time"
"github.com/spikerlabs/godog/colors"
"github.com/spikerlabs/godog/gherkin"
)
var sampleGherkinFeature = `
Feature: junit formatter
Background:
Given passing
Scenario: passing scenario
Then passing
Scenario: failing scenario
When failing
Then passing
Scenario: pending scenario
When pending
Then passing
Scenario: undefined scenario
When undefined
Then next undefined
Scenario Outline: outline
Given <one>
When <two>
Examples:
| one | two |
| passing | passing |
| passing | failing |
| passing | pending |
Examples:
| one | two |
| passing | undefined |
`
func TestJUnitFormatterOutput(t *testing.T) {
feat, err := gherkin.ParseFeature(strings.NewReader(sampleGherkinFeature))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var buf bytes.Buffer
w := colors.Uncolored(&buf)
s := &Suite{
fmt: junitFunc("junit", w),
features: []*feature{&feature{
Path: "any.feature",
Feature: feat,
Content: []byte(sampleGherkinFeature),
}},
}
s.Step(`^passing$`, func() error { return nil })
s.Step(`^failing$`, func() error { return fmt.Errorf("errored") })
s.Step(`^pending$`, func() error { return ErrPending })
var zeroDuration time.Duration
expected := junitPackageSuite{
Name: "junit",
Tests: 8,
Skipped: 0,
Failures: 2,
Errors: 4,
Time: zeroDuration.String(),
TestSuites: []*junitTestSuite{{
Name: "junit formatter",
Tests: 8,
Skipped: 0,
Failures: 2,
Errors: 4,
Time: zeroDuration.String(),
TestCases: []*junitTestCase{
{
Name: "passing scenario",
Status: "passed",
Time: zeroDuration.String(),
},
{
Name: "failing scenario",
Status: "failed",
Time: zeroDuration.String(),
Failure: &junitFailure{
Message: "Step failing: errored",
},
Error: []*junitError{
{Message: "Step passing", Type: "skipped"},
},
},
{
Name: "pending scenario",
Status: "pending",
Time: zeroDuration.String(),
Error: []*junitError{
{Message: "Step pending: TODO: write pending definition", Type: "pending"},
{Message: "Step passing", Type: "skipped"},
},
},
{
Name: "undefined scenario",
Status: "undefined",
Time: zeroDuration.String(),
Error: []*junitError{
{Message: "Step undefined", Type: "undefined"},
{Message: "Step next undefined", Type: "undefined"},
},
},
{
Name: "outline #1",
Status: "passed",
Time: zeroDuration.String(),
},
{
Name: "outline #2",
Status: "failed",
Time: zeroDuration.String(),
Failure: &junitFailure{
Message: "Step failing: errored",
},
},
{
Name: "outline #3",
Status: "pending",
Time: zeroDuration.String(),
Error: []*junitError{
{Message: "Step pending: TODO: write pending definition", Type: "pending"},
},
},
{
Name: "outline #4",
Status: "undefined",
Time: zeroDuration.String(),
Error: []*junitError{
{Message: "Step undefined", Type: "undefined"},
},
},
},
}},
}
s.run()
s.fmt.Summary()
var exp bytes.Buffer
if _, err = io.WriteString(&exp, xml.Header); err != nil {
t.Fatalf("unexpected error: %v", err)
}
enc := xml.NewEncoder(&exp)
enc.Indent("", " ")
if err = enc.Encode(expected); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if buf.String() != exp.String() {
t.Fatalf("expected output does not match: %s", buf.String())
}
}