seniorClean Architecture
Testing the 'Ports' with Spy/Stub.
Updated Apr 28, 2026
Short answer
Use Stubs to provide controlled input to the Use Case and Spies to verify the Use Case's output to the Port.
Deep explanation
When testing a Use Case, you don't use a real database. You provide a 'Stub' of the Repository that returns specific entities. You can also use a 'Spy' to ensure that the save method was called with the correct data after the business logic ran.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro