FAST - 빠르게
- 테스트는 빠르게 동작할 수 있어야 함.
- 실제 프로젝트에서는 수많은 테스트 코드를 작성하게 될 텐데 테스트가 느리게 동작한다면 테스트를 실행하는 데에만 몇 분의 시간이 소요됨.
- 테스트 코드는 빠르게 확인하고, 수정하고 반영하는 데에 큰 의미가 있기 때문에 속도가 느린 테스트는 테스트 코드의 의미 중 많은 부분을 잃어버린 것과 같다고 볼 수 있음.
Independent / Isolated - 독립적으로
- 각각의 테스트는 서로 독립적이며 서로 의존해서는 안 됨.
- 좋은 단위 테스트는 최소한의 단위의 테스트에 집중할 수 있게 각 테스트들이 서로에게 영향을 주어서는 안됨.
- 만약 다른 코드에 의존성이 높거나 영향을 많이 주고받고 있는 경우에는 완전히 통제된 상황에서 테스트를 진행하기 어려울 수 있으며 테스트가 실패하게 되었을 경우 그 원인이 불분명한 경우가 발생할 수 있음.
Repeatable - 반복 가능하게
- 테스트는 언제 어디서나 같은 결과가 반복되어야 함.
- 이를 위해서 통제가 어려운 부분에 대해서는 테스트를 위한 객체를 만들어주는 방법을 선택하기도 함.
- 즉 모든 환경을 통제하여 매번 예상한 결과대로 테스트가 진행되게 해야 함.
Self-Validating - 스스로 검증하는
- 테스트는 Bool을 이용하여 성공/실패에 대해서 스스로 검증이 가능해야 함
- 테스트 코드 내부에서 이 테스트가 잘 동작했는지를 판별할 수 있어야 함.
Timely - 적시에
- 이상적인 테스트는 테스트하려는 실제 코드를 구현하기 직전에 구현해야 함.