You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importBfuncfA(in) out{
...resp :=B.fB(p1, p2)
...
}
TEST
package A
importbmockfuncTestfA(t*testing.T) {
typemockBstruct {
resp// mock resp of B.fBtimes// number of times B.fB will be called
}
testCases:= []struct {
nameargsmockBwant
} { // add testcases }for_, tc:=rangetestCases {
t.Run(tc.name, func(t*testing.T) {
gmc:=gomock.NewController(t)
defergmc.Finish()
bStub:=bmock.NewMockService(t) // just an example, this is debatablebstub.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.
Hi @chatrasen, while personally I'm not the biggest fan of mocks (I prefer fakes and stubs), I understand that many Go programmers would love to have this feature. I also see that goland/mock is very popular.
I will approve a PR introducing this feature, as long as it is disabled by default, and enabled by a flag like --automock='mock', so that we can extend this to use other mocking libraries in the future.
Reacted by Johan Lejdung, Santiago De la Cruz, samyakjain-grabtaxi and Agility6
I'm using mockery and are very interested in trying this package out! It would be amazing to get some generated code with support for mockery mocks as well 🙏
Following with great interest
Reacted by Tushar singune, samyakjain-grabtaxi and Agility6
Hi @chatrasen, while personally I'm not the biggest fan of mocks (I prefer fakes and stubs), I understand that many Go programmers would love to have this feature. I also see that goland/mock is very popular.
I will approve a PR introducing this feature, as long as it is disabled by default, and enabled by a flag like --automock='mock', so that we can extend this to use other mocking libraries in the future.
Activity
cweill commentedon Feb 22, 2021
Hi @chatrasen, while personally I'm not the biggest fan of mocks (I prefer fakes and stubs), I understand that many Go programmers would love to have this feature. I also see that goland/mock is very popular.
I will approve a PR introducing this feature, as long as it is disabled by default, and enabled by a flag like
--automock='mock', so that we can extend this to use other mocking libraries in the future.johan-lejdung commentedon Mar 9, 2021
I'm using mockery and are very interested in trying this package out! It would be amazing to get some generated code with support for mockery mocks as well 🙏
Following with great interest
Agility6 commentedon Nov 11, 2025
Hi, how is this feature going?
Agility6 commentedon Nov 11, 2025
Hi! I would like to try to implement this feature