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.

Figure 9.1. The progression of this chapter’s sections

9.1. Testing your domain model

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.

9.2. Designing testable domain models

9.3. xUnit-based testing

9.4. Revisiting the algebra of your model

9.5. Property-based testing

9.6. Summary

sitemap