mockery icon indicating copy to clipboard operation
mockery copied to clipboard

How to put mocks inside package dir in separate test package (with _test suffix)

Open georgysavva opened this issue 4 years ago • 2 comments

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?

georgysavva avatar Jun 25 '20 12:06 georgysavva

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.

LandonTClipp avatar Jun 25 '20 14:06 LandonTClipp

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?

georgysavva avatar Jun 25 '20 14:06 georgysavva

Closing this ticket, as this will be easily doable when using the packages feature.

LandonTClipp avatar Apr 06 '23 21:04 LandonTClipp