Verification by Injection

All but the outermost components of our system—the leaf components—rely on other components to accomplish their tasks. These other components are called collaborators, or Depended-On Components (DOCs) in Meszaros’s terminology [xTP]. Whether writing unit tests that test only the value added or when testing an integrated system, you often need to create substitutes for collaborators, known as test doubles. Especially at the unit level, injection is the most common way to introduce test doubles.

Generally speaking, dependency injection is the software-design pattern in which collaborators are inserted (i.e., injected) at runtime to satisfy the needed functionality. When testing, we can leverage various forms of dependency ...

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.