Chapter 9. Testing your domain model
This chapter covers
- Designing testable domain models
- Learning why xUnit-based testing isn’t enough
- Introducing property-based testing
- Using properties as executable blueprints for domain behaviors
This chapter covers testing your domain model. I begin with an explanation of what is meant by a testable model and how testability is related to the modularity of a model architecture. I take examples from some of the model components discussed in earlier chapters and look at how to test them. Then I discuss briefly the shortcomings of xUnit-based testing and dive into the details of property-based testing using ScalaCheck.
Figure 9.1 diagrams the chapter content.
Before delving into testing domain models, you first need to understand what exactly I mean by testability. After all, a group of team members manually harnessing your domain model with reams of test data is also doing testing. But that’s not the definition of testing that we’re using here. The main problem with manual testing is that it’s not repeatable. After you make changes to your domain-model implementation, how do you ensure that it still works as per the specification? Would you employ the same set of testing team members and repeat the entire ceremony? How do you find out which parts of the model have been impacted by the changes that you made last night? Manual testing is no testing.