Testing a domain entity with unit tests
We will start by looking at a domain entity at the center of our architecture. Let’s recall the Account entity from Chapter 5, Implementing a Use Case. The state of Account consists of a balance an account had at a certain point in the past (the baseline balance) and a list of deposits and withdrawals (activities) made since then.
We now want to verify that the withdraw() method works as expected:
The preceding test is a plain unit test that instantiates an Account in a specific state, calls its withdraw() method, and verifies that the withdrawal was successful and had the expected side effects on the state of the Account object under test.
The test is rather easy to set up, is easy to understand, and runs very fast. Tests don’t come much simpler than this. Unit tests such as these are our best bet to verify the business rules encoded within our domain entities. We don’t need any other type...