← Graph

Inject test doubles via dependency injection

takeaway 3 connections

When stubbing methods couples tests to implementation, extract an interface (e.g. `Dice`) and dependency-inject an implementation. Production code passes the real class; tests pass a fake whose outputs are scripted. Benefits: code stays open for extension, tests remain deterministic, refactoring is easier. Costs: more code in tests, the fake must be kept in sync with the real class, and picking the wrong abstraction early makes future change expensive.

type
recommendation
takeaway Inject test doubles via dependency injection
about
Recommendation is a direct application of DI to testing.
takeaway Inject test doubles via dependency injection
about
Fake Object concept
The injected collaborator is a fake implementation.
takeaway Inject test doubles via dependency injection
from_talk
Summary of the third-iteration analysis.

Provenance

Read by
2 extractions