-
Notifications
You must be signed in to change notification settings - Fork 409
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
Is it possible to mock a class from the standard library? #19
Comments
Hey @miloconway, mockery seems prepared to create mocks for your interfaces rather than from the standard library. However, you can checkout the Go repo, generate the mock, and copy it to your project. Here's one generated for import "github.com/stretchr/testify/mock"
type MockRoundTripper struct {
mock.Mock
}
func (m *MockRoundTripper) RoundTrip(_a0 *Request) (*Response, error) {
ret := m.Called(_a0)
var r0 *Response
if ret.Get(0) != nil {
r0 = ret.Get(0).(*Response)
}
r1 := ret.Error(1)
return r0, r1
} |
mockery could be setup to parse other packages to generate mocks, but if you want to mock an interface usually you want some control over it and thus copying the interface into your package is better way to handle that. |
I see, thank you for the clarification |
I'd like to be able to generate mocks for other libraries. Copying interfaces into my own code seems like a reasonable workaround, but it would be nice if this were a first-class feature. Example annoyance:
Not hard, but kind of annoying to track down. |
@wolfgangmeyers, I've got to spend some time this weekend reviewing and documenting the tool, but you can We switched from |
@ernesto-jimenez Would you be willing to merge mockery and goautomock? Combining forces might be good! |
+1 |
@evanphx, that was my initial approach from issue #41, but you mentioned you didn't want to require Go 1.5 :) I'm maintaining It might be worth while converging into testify itself. I'm the maintainer and never create mocks by hand. |
Ah! I'd love to merge mockery into testify. I think that Go 1.5 has probably been around long enough now that it's ok to require it. How can we make this happen? |
Opened an issue in testify: stretchr/testify#273 |
I'm updating mockery to use |
any news on this.. |
The pattern here is to do something like this:
And use |
No you can just mock packages:
io:
interfaces:
Writer: |
Is there a command line equivalent? |
There is not, you have to use the packages feature. |
For example, want to generate a mock for "net/http" RoundTripper
The text was updated successfully, but these errors were encountered: