liveBook · Manning

Design for testability

As explained in Microservices Patterns, Second Edition

Design for testability is the practice of structuring software so that its behavior and properties can be verified efficiently through automated tests.

Design for testability structures software so developers can write and run automated tests easily. Fast feedback helps teams assess whether changes are releasable without waiting for slower, error-prone manual testing. section 5.4.3

Use three design strategies to make automated testing easier:

  • Structure software as small elements with loose design-time coupling; stable APIs also reduce test updates. section 5.4.3
  • Eliminate or limit nondeterminism, ideally isolating nondeterministic code in its own component. section 5.4.3
  • Use dependency injection to replace troublesome dependencies with test doubles; functional-style programming is another suggested technique. section 5.4.3

For faster test runs, testability is one of several architectural characteristics associated with reducing retesting scope and test-suite execution time. section 5.4.4

Figure 5.15 A subdomain’s clients should depend on the more stable API build project rather than the less stable implementation build project. In this example, the order-management-impl build project does not need to be rested when the customer-management-impl build project changes.
reduce build time coupling

A stable API build project can keep clients from depending on a changing implementation project, limiting which projects need retesting after a change. section 5.4.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines three design strategies but stops short of a complete implementation example.
Examples
Uses test doubles for troublesome dependencies and a stable API boundary to limit retesting after implementation changes.
What you can do after
Apply it by building small, loosely coupled elements, limiting nondeterminism, and replacing troublesome dependencies with test doubles.
How it connects
Connects automated testing with stable APIs, nondeterminism, dependency injection, functional-style programming, and test doubles.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.