테스트 악취

단위 테스트에서 나는 코드 악취:

Here are some attributes of tests that suggest a design in trouble.

  • Long setup code: If you have to spend a hundred lines creating the objects for one simple assertion, then something is wrong. Your objects are too big and need to be split.
  • Setup duplication: If you can’t easily find a common place for common setup code, then there are too many objects too tightly intertwined.
  • Long running tests: TDD tests that run a long time won’t be run often, and often haven’t been run for a while, and probably don’t work. Worse than this, they suggest that testing the bits and pieces of the application is hard. Difficulty testing bits and pieces is a design problem, and needs to be addressed with design. (The equivalent of 9.8m/s29.8 m/s^2 is the ten-minute test suite. Suites that take longer than ten minutes inevitably get trimmed, or the application tuned up, so the suite takes ten minutes again.)
  • Fragile tests: Tests that break unexpectedly suggest that one part of the application is surprisingly affecting another part. You need to design until the effect at a distance is eliminated, either by breaking the connection or by bringing the two parts together.

—Chapter 32, Test-driven development: by example

See also

2024 © ak