-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
49 lines (40 loc) · 976 Bytes
/
example_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
package testit_test
import (
"testing"
"github.com/sonalys/testit"
)
func Test_Example(t *testing.T) {
type dependency struct {
// mock *mock.Mock // Mocks are automatically initialized
}
type tc struct{}
setup := testit.SetupWithTestCase(func(t *testit.CHook[dependency, tc]) {
// setup, pre-cleanup.
// t.Dependencies.mock.EXPECT().DoSomething()
t.After = func() {
// teardown
}
})
withHook := setup.Hook(func(t *testit.CHook[dependency, tc]) {
// additional hook
t.After = func() {
// additional teardown
}
})
additionalStep := func(t testit.DCTest[dependency, tc]) {}
testfunc := func() (int, error) {
return 0, nil
}
t.Run("example", withHook.Case(tc{},
// any additional steps can be added manually as well.
additionalStep,
func(t testit.DCTest[dependency, tc]) {
// test execution
var err error
t.NoError(err)
t.FailNow("failing test")
value := testit.NoErr(testfunc())
t.Equal(0, value)
},
))
}