Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please make a public generator for testify mocks akin to https://github.com/matryer/moq #728

Open
scr-oath opened this issue Feb 15, 2019 · 5 comments
Projects

Comments

@scr-oath
Copy link

https://github.com/matryer/moq generates a mock from an interface which, though nice, isn't as rich a mocking language as testify (ability to just say how many times, or return what as part of test).

It would be great if testify could provide a means of generating, for instance, from:

type MyInterface interface {
  DoSomething(int) (int, error)
}

this:

type MyInterfaceMock struct {
  mock.Mock
}

func (m *MyInterfaceMock) DoSomething(in1 int) (int, error) {
    replyArgs := m.Called(in1)
    return replyArgs.Int(0), replyArgs.Error(1)
}
@HaywardMorihara
Copy link

HaywardMorihara commented Feb 16, 2019

I agree, would be lovely to have it right in testify

But, until that's a reality, you could always try https://github.com/vektra/mockery. I've used it with success so far

@scr-oath
Copy link
Author

scr-oath commented Feb 16, 2019 via email

@sagikazarmark
Copy link

Unfortunately vektra/mockery does not seem to be maintained. I agree it would be somewhat better if this package provided a solution OOTB.

@alexejk
Copy link

alexejk commented Jan 14, 2020

I am forced to remove vektra/mockery in most places as it seems to be causing quite a bit of issues (OOMs in containers etc) and requires to vendor dependencies to mock 3rd-party packages. Luckily in my case it's fairly easy to hand-mock things.

Would love to have an out of the box solution for it that also works with modules.

@sagikazarmark
Copy link

I've built a tool for generating code and added support for generating testify mocks:

https://github.com/sagikazarmark/mga#testify-mock-generator

It works well with modules as well.

I'm working on better documentation for the project, but the tool already works and generates mocks in a real life project.

@mvdkleijn mvdkleijn added this to Evaluate / Should it be done? in Roadmap via automation Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Roadmap
  
Evaluate / Should it be done?
Development

No branches or pull requests

4 participants