본문 바로가기

computer/develop

TDD - Test Driven Development

TDD

  1. Write a test of the new code and see it fail.
  2. Write the new code, doing "the simplest thing that could possibly work."
  3. See the test succeed, and refactor the code.

New code should only be written when a test fails. Code chages are only expected to occur when you are refactoring, adding new functionality, or debugging.

When adding new functionality, the first step is always to write a unit test that anticipates and uses the new code. After the unit test runs and fails, add the new code and re-test to verify success. The unit test has value aside from simply demonstaring that the new functionality works. Writing the test forces you to think in advance about the ideal design of the new code.

실패하는 테스트 코드를 적는다는 것은 절반의 완성을 의미한다.