- 우리는 가장 의미있는 테스트(general case)를 제일 먼저 떠올린다.
- 하지만 그런 테스트는 구현이 복잡하고, 그런 기능을 제일 먼저 구현하면 예외적인 경우들이 누락되는 현상이 발생하기 쉽다.
- tdd에서는 functional decomposition을 통해서 가장 단순한 테스트(special case)부터 추가해 가면서 최종적으로 general case에 도달하기 위한 stair step tests 목록을 작성하게 됨
- 절차
- most simple and degenerate(special)에서 시작
- null, empty, 0, boundary, simple stuff 등과 같은 special case
- 다음 단계로 interesting 하지만 조금 덜 degenerate한 테스트 케이스(단일 아이템, 최소 유효 값 등)를 점진적으로 추가
- 마지막에 most interesting(general), 복잡한 테스트 케이스(복잡한 비즈니스 로직. 다중 할인 계산, 경계 값 케이스 등)를 추가해줘
- most simple and degenerate(special)에서 시작
- 초래되는 결과
- 가장 쉬운 경우에서 시작해서 본질적은 목표인 high level test로 incremental하게 진행되도록 테스트를 추가하게 됨
- tdd의 원칙 중 하나인 "as the tests get more specific, the code gets more generic"가 준수됨
- production code는 guard clause가 적용되어 앞부분에 예외적인 경우(special case)들이 처리되고, 마지막에 중요한 기능(general case)이 구현되어 indentation이 줄어들어 인지 부하가 줄어드는 효과가 있음
- 함수의 pre codition이 명확해지는 효과가 있음
Created
May 19, 2025 06:08
-
-
Save msbaek/4c14682282adc82b648fabc0fdf17d2e to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment