You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow Generated Mocks to Accept Other Mock Interfaces as Input to Avoid Cyclic Imports #208
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.
changed the title [-]Generated Mocks in Separate Package Cause Cyclic Import When Used in Main Package[/-][+]Allow Generated Mocks to Accept Other Mock Interfaces as Input to Avoid Cyclic Imports[/+]on Oct 2, 2024
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{}
Activity
[-]Generated Mocks in Separate Package Cause Cyclic Import When Used in Main Package[/-][+]Allow Generated Mocks to Accept Other Mock Interfaces as Input to Avoid Cyclic Imports[/+]tulzke commentedon Oct 2, 2024
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{}
tulzke commentedon Oct 2, 2024
Possible solutions to the problem:
_testpostfix for package in tests. Then the dependency graph will look like this: