forked from ozontech/allure-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fails_test.go
220 lines (176 loc) · 6 KB
/
fails_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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//go:build examples_new
// +build examples_new
package suite_demo
import (
"testing"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)
type FailsDemoSuite struct {
suite.Suite
}
func (s *FailsDemoSuite) BeforeEach(t provider.T) {
t.Epic("Demo")
t.Feature("Failures")
}
func (s *FailsDemoSuite) TestAssertionFail(t provider.T) {
t.Title("This test failed by assert with message")
t.Description(`
This Test will be failed with assert Error.
Error text: Assertion Failed`)
t.Tags("fail", "assertions")
t.Require().Equal(1, 2, "Assertion Failed")
}
func (s *FailsDemoSuite) TestXSkipFail(t provider.T) {
t.Title("This test skipped by assert with message")
t.Description(`
This Test will be skipped with assert Error.
Error text: Assertion Failed`)
t.Tags("fail", "xskip", "assertions")
t.XSkip()
t.Require().Equal(1, 2, "Assertion Failed")
}
func (s *FailsDemoSuite) TestAssertionFailNoMessage(t provider.T) {
t.Title("This test failed by assert without message")
t.Description(`
This Test will be failed with assert Error.
Error text:
Not equal:
expected: 1
actual : 2`)
t.Tags("fail", "assertions")
t.Require().Equal(1, 2)
}
func (s *FailsDemoSuite) TestAssertionFailInnerSteps(t provider.T) {
t.Title("This test failed by assert with inner step")
t.Description(`
This Test will be failed with assert Error.
Error text:
Not equal:
expected: 1
actual : 2`)
t.Tags("fail", "assertions", "nesting")
t.WithNewStep("Failed parent step", func(ctx provider.StepCtx) {
ctx.WithNewStep("Failed child step", func(ctx provider.StepCtx) {
ctx.Require().Equal(1, 2, "Failed inside step")
})
})
}
func (s *FailsDemoSuite) TestPanic(t provider.T) {
t.Title("This test panicked")
t.Description(`
This Test will Failed by panic.
Error text:
test panicked: runtime error: index out of range [0] with length 0 goroutine 8 [running]:...`)
t.Tags("fail", "panic")
var test []string
test2 := test[0]
t.Require().Equal(test2, test2, "Never reach this")
}
func (s *FailsDemoSuite) TestPanicInnerSteps(t provider.T) {
t.Title("This test panicked with inner steps")
t.Description(`
This Test will Failed by panic.
All steps that includes error will be failed
Error text:
test panicked: runtime error: index out of range [0] with length 0 goroutine 8 [running]:...`)
t.Tags("fail", "panic", "nesting")
t.WithNewStep("Check 1", func(ctx provider.StepCtx) {
ctx.WithNewStep("Check 1.1", func(ctx provider.StepCtx) {
})
ctx.WithNewStep("Check 1.2", func(ctx provider.StepCtx) {
ctx.WithNewStep("Check 1.2.1", func(ctx provider.StepCtx) {
var test []string
test2 := test[0]
ctx.Require().Equal(test2, test2, "Never reach this")
})
})
})
}
func (s *FailsDemoSuite) TestBrokenStatusNoMessage(t provider.T) {
t.Title("This test fails with broken status")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken")
t.NewStep("This step will be reached before failing")
t.Broken()
t.NewStep("This step will be reached after failing")
}
func (s *FailsDemoSuite) TestBrokenNowStatusNoMessage(t provider.T) {
t.Title("This test fails immediately with broken status")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken")
t.NewStep("This step will be reached before failing")
t.BrokenNow()
t.NewStep("This step will never be reached after failing")
}
func (s *FailsDemoSuite) TestBrokenNowStatusMessage(t provider.T) {
t.Title("This test fails immediately with broken status and message")
t.Description(`
This Test will Failed as FailNow().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken")
t.NewStep("This step will be reached before failing")
t.Breakf("Test fails as FailNow()")
t.NewStep("This step will never be reached after failing")
}
func (s *FailsDemoSuite) TestBrokenStatusNoMessageStep(t provider.T) {
t.Title("This test fails with broken status inside step")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken")
t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.Broken()
})
t.NewStep("This step will be reached after failing")
}
func (s *FailsDemoSuite) TestBrokenNowStatusNoMessageStep(t provider.T) {
t.Title("This test fails immediately with broken status inside step")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken")
t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.BrokenNow()
})
t.NewStep("This step will never be reached after failing")
}
func (s *FailsDemoSuite) TestBrokenNowStatusMessageStep(t provider.T) {
t.Title("This test fails immediately with broken status and message inside step")
t.Description(`
This Test will Failed as FailNow().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken")
t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.Breakf("Test fails as FailNow()")
})
t.NewStep("This step will never be reached after failing")
}
func (s *FailsDemoSuite) TestBrokenNowStatusMessageInnerStep(t provider.T) {
t.Title("This test fails immediately with broken status and message inside inner step")
t.Description(`
This Test will Failed as FailNow().
Test status will be "Broken" in allure.
No any message expected there`)
t.Tags("fail", "broken", "inner")
t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.WithNewStep("Inner step", func(sCtx provider.StepCtx) {
sCtx.Breakf("Test fails as FailNow()")
})
})
t.NewStep("This step will never be reached after failing")
}
func TestFails(t *testing.T) {
t.Parallel()
suite.RunSuite(t, new(FailsDemoSuite))
}