Testing a Use Case with Unit Tests

Learn how to test use cases with the help of unit tests.

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.

Send money service test

We want to make sure that everything works as expected when the transaction succeeds:

Get hands-on with 1400+ tech skills courses.