-
Notifications
You must be signed in to change notification settings - Fork 346
Open
Labels
Description
Majority of the functions involve calls to functions from external packages which need to be mocked. Adding support for mocks can take gotests
to the next level I believe.
e.g. An example function and its generated test can look something like this (pseudocode)
CODE
package A
import B
func fA(in) out{
...
resp := B.fB(p1, p2)
...
}
TEST
package A
import bmock
func TestfA(t *testing.T) {
type mockB struct {
resp // mock resp of B.fB
times // number of times B.fB will be called
}
testCases := []struct {
name
args
mockB
want
} { // add testcases }
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
gmc := gomock.NewController(t)
defer gmc.Finish()
bStub := bmock.NewMockService(t) // just an example, this is debatable
bstub.Expect().fB(gomock.Any(), gomock.Any()). // 2 params so 2 gomock.Any()
Times(tc.mockB.times).
Return(tc.mockB.resp)
...... // existing logic follows
})
}
}
I would first like to ask whether you have already thought about the feasibility of this idea. If you feel this is possible, I would love to work on this enhancement.
piotrekmonko