Chapter 8. Encapsulation and Override Variations

Chapter 6 introduced a technique to encapsulate functionality in such a way that we could override it for better control while testing. This chapter elaborates on that approach with several variations. We use encapsulation to create seams in our code that can then be exploited for verification. We also look at the use of test doubles (see the sidebar “Test Doubles and Interface-Based Design”) to help us.

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.