mockery
mockery copied to clipboard
How to put mocks inside package dir in separate test package (with _test suffix)
I want to put generated mocks in *_test.go
files inside my package directory, but in separate test package with _test
suffix. I tried this command:
mockery --inpackage --testonly --name "MyInterface"
It creates mock_MyInterface_test.go
file as I want, but it has package without the _test
suffix. It's okay for the default behaviour, but how can I override it? I tried this:
mockery --inpackage --testonly --outpkg "mypackage_test" --name "MyInterface"
But it had no effect and created mock_MyInterface_test.go
with mypackage
packge.
Is there a convenient way to put mocks in *_test
package?
So --inpackage
certainly won't work because you're trying to put them in a different package (one with _test
as the suffix). I don't know off the top of my head if this is possible. I'll have a think on it.
Thanks! I could come up only with this:
mockery --output . --structname MockMyInterface --filename mock_MyInterface_test.go --outpkg mypackage_test --name "MyInterface"
It does exactly what I want, but it looks a bit hacky and verbose. What do you think?
Closing this ticket, as this will be easily doable when using the packages feature.