Testing a Use Case with Unit Tests
Explore how to unit test use cases within Hexagonal Architecture, focusing on verifying interactions with dependencies using mock objects. Understand structuring tests with given/when/then for clarity and consider balancing interaction checks to maintain test utility and adaptability when refactoring.
We'll cover the following...
We'll cover the following...
The next architecture element to test is the use cases. Let’s look at a test of the SendMoneyService discussed in the chapter “Implementing a Use Case”.
The “Send Money” use case locks the source Account so no other transaction can
change its balance in the meantime. If we can successfully withdraw the money from the source account, we lock the target account as well and deposit the money there. Finally, we unlock both accounts again.