Allow Generated Mocks to Accept Other Mock Interfaces as Input to Avoid Cyclic Imports
Requested feature
Consider two interfaces, InterfaceA and InterfaceB. InterfaceA has a function that takes an object of InterfaceB as input. I want to generate MockInterfaceA, with the function accepting MockInterfaceB as input instead of InterfaceB.
Why the feature is needed If the generated mock files are placed in a separate folder, and the mocked interface is used in a test file located in the main package, it will result in a cyclic import: main package -> mock package -> main package.
Here is a simple example why this does not work: example.zip
TL;DR: // compilation error // Type HumanMock does not implement Human // need the method: Call(dog Dog) // have the method: Call(_ DogMock) var human Human = mock.HumanMock{}
Possible solutions to the problem:
- Generate mocks to the same directory as interfaces.
- Use the
_testpostfix for package in tests. Then the dependency graph will look like this:
flowchart LR
some_package
mock --> some_package
some_package_test --> some_package
some_package_test --> mock