-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
62 lines (52 loc) · 991 Bytes
/
testing.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
package testing
import (
"fmt"
"testing"
)
type TestSuite interface {
Execute()
Before(func()) TestSuite
After(func()) TestSuite
Test(name string, test func()) TestSuite
Context() *testing.T
}
type testItem struct {
Name string
TestFunc func()
}
type testSuite struct {
before func()
after func()
test []testItem
t *testing.T
}
func NewTestSuite(t *testing.T) TestSuite {
return &testSuite{t: t}
}
func (t *testSuite) Context() *testing.T {
return t.t
}
func (t *testSuite) Before(before func()) TestSuite {
t.before = before
return t
}
func (t *testSuite) After(after func()) TestSuite {
t.after = after
return t
}
func (t *testSuite) Test(name string, test func()) TestSuite {
t.test = append(t.test, testItem{Name: name, TestFunc: test})
return t
}
func (t *testSuite) Execute() {
if nil != t.before {
t.before()
}
if nil != t.after {
t.after()
}
for _, f := range t.test {
fmt.Printf("=== Testing: %s\n", f.Name)
f.TestFunc()
}
}