In 30 Sekunden
Dave Farley discusses meaningless assertions, excessive setup, giant tests, over-mocking and tests that inspect private internals. He argues that focused tests and better separation of concerns can turn testing difficulty into design feedback.
- 1The liarA passing test without a useful assertion can create false confidence.
- 2Excessive setupComplicated setup can reveal difficult dependencies.
- 3The giantA large test can obscure which behavior failed.
- 4The mockeryMocking everything may leave no real behavior under test.
- 5The inspectorAssertions tied to private internals can make tests fragile.
Das Wichtigste
- A passing test without a useful assertion can create false confidence.
- Complicated setup can reveal difficult dependencies.
- A large test can obscure which behavior failed.
- Mocking everything may leave no real behavior under test.
- Assertions tied to private internals can make tests fragile.
Den bearbeiteten Text nach Kapiteln lesen
Testing as design feedback
Farley introduces the purpose of the feedback loop.
Dave Farley argues that difficulties in test-driven development can signal problems in software design. In this 2021 talk he examines five testing anti-patterns and proposes ways to make feedback more useful.
For Farley, TDD’s value is not just a coverage number: writing tests and code in a short feedback loop can expose coupling, poor separation of concerns and difficult interfaces. These signals still require judgment about the context.
Meaningless tests and setup
The first two patterns expose weak assertions and difficult dependencies.
The first anti-pattern, “the liar,” is a test that passes but makes no meaningful assertion. He recalls a coverage target that encouraged tests which executed code without checking useful behavior.
His suggested correction is to remove or improve meaningless tests and observe a new test fail for the intended reason before implementing the behavior. A failing test is useful evidence, though it alone does not guarantee the test is correct.
“Excessive setup” occurs when preparing a test takes a large amount of work. Farley treats this as a prompt to inspect dependencies and separation of concerns, rather than immediately accepting a fragile setup.
He shows a test that starts an entire Jenkins environment to check a URL string. For that particular behavior, a smaller unit-level check may be faster and clearer; broader integration tests can still be appropriate when the interaction itself matters.
Large tests and mocks
He discusses unclear intent and overuse of test doubles.
“The giant” is a long test with many assertions and unclear intent. Farley says failures can be hard to diagnose when unrelated behaviors are bundled into one case.
He prefers decomposing such cases into focused tests and suggests one assertion per test as a rule of thumb. Multiple related assertions can also be reasonable when they describe one coherent behavior.
“The mockery” relies on so many mocks or stubs that little or no production behavior is exercised. In his example both the car and engine are mocked, leaving a test of the configured doubles rather than their real implementation.
He recommends reconsidering the design and focusing on the behavior the software must provide. Test doubles can be useful at a boundary, but they should not replace the behavior the test is meant to verify.
Encapsulation and behavior
The final pattern concerns tests coupled to internal details.
“The inspector” breaks encapsulation to assert private implementation details. Farley warns that tests coupled to internals may fail after harmless refactoring even when externally observable behavior remains correct.
He shows a method apparently added only for a test and asks whether a better abstraction or dependency boundary would let the test observe behavior without exposing private state. That is a design question, not a prohibition on all test-specific instrumentation.
Across the five patterns, his theme is to use testing friction as feedback: simplify setup, clarify behavior, improve separation and avoid treating coverage as the goal itself.
Mehr aus diesem Kanal
39:12EN
22:33EN
34:11EN
28:15EN
46:36EN
28:23EN