Encapsulation, Observability, and Testability

All in all, conventional guidance about object-oriented encapsulation creates a tension between good design and testability. The testability of a class directly relates to your ability to verify its state, hidden behind getters and setters, and its behavior, hidden in restricted methods.

In an ideal world, our programming languages would support testability needs. Increasingly, frameworks make provisions for testability and tools leverage language features to increase our ability to test. In the meantime, our job is to find a balance between the rules of good design and the need for verification.

This book advocates using language and tool features where possible to test our code. Where standard language ...

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.