This question is a follow-up question to Clean Architecture use case testing.
Suppose the production code injects Use Case Interactor into the Input Boundary - that happens somewhere in the main component1. But now I want to test the Input Boundary/Output Boundary of the use case. I can only think of two ways to do this:
- Recreate the dependency injection setup at the beginning of the test - this forces the test to depend on
Use Case Interactor. - Depend on the main component for DI - this seems risky because the main component is volatile.
Is there a clean way to handle this situation?
1 Clean Architecture Chapter 26, Robert C Martin

InputBoundaryin isolation, or do you want to create an integration test forInputBoundaryandUseCaseInteractor? – Doc Brown Jul 29 '21 at 16:01InputBoundarywhich depends onUseCaseInteractor- so to testInputBoundaryyou must pass instance ofUseCaseInteractor. It is ok for test to depend on input parameters (UseCaseInteractoris an input parameter ofInputBoundarywhich passed via constructor). – Fabio Jul 30 '21 at 05:31UseCaseInteractoris an input parameter ofInputBoundary".InputBoundaryis an interface, it doesn't have a constructor. I spent some more time looking at clean architecture and I think it would be best to testUseCaseInteractordirectly, rather than throught the boundaries. – Brady Dean Jul 30 '21 at 15:59UseCaseInteractoras a constructor argument (I assume) – Fabio Jul 30 '21 at 21:10ControllerandPresenter. It drives the system (use case) throughInputBoundary, and verifies the result through theOutputBoundary/Presenter. However, in the situation whereUseCaseInteractormust be injected I am unsure of how to write this test harness. Should the test manually instantiateUseCaseInteractor, or should the test require it to be injected? – Brady Dean Jul 30 '21 at 21:55UseCaseInteractor. – Brady Dean Jul 30 '21 at 21:57