即使出于好意,团队也常常陷入测试反模式的陷阱——这些做法会使测试变得脆弱、缓慢、不可信或低价值。认识并避免这些反模式对维护一个健康、有价值的测试套件至关重要。
测试质量反模式
✗ TESTING IMPLEMENTATION DETAILS → tests coupled to internals → break on every refactor
(brittle) → test BEHAVIOR/outcomes instead
✗ FLAKY tests → intermittent failures erode trust → people ignore failures (real ones too)
✗ OVER-MOCKING → mocking everything → tests verify mock interactions, not real behavior;
brittle and give false confidence
✗ Tests with NO meaningful assertions → run code but verify nothing (false coverage)
✗ GIANT tests checking many things → unclear what failed; hard to maintain
结构和战略反模式
✗ ICE CREAM CONE → mostly slow E2E/manual, few unit tests → slow, brittle, expensive suite
✗ INTERDEPENDENT tests / shared mutable state → order-dependent, flaky, fragile
✗ Testing the FRAMEWORK / trivial code → low value; testing what doesn't need testing
✗ Chasing COVERAGE numbers → low-value tests written just to hit a percentage
✗ Slow tests → discourage running them → defeats fast-feedback value
