함수형
-
단위 테스트 정리 4 - 목과 테스트 취약성책책책 책을 읽읍시다/프로그래밍 2022. 7. 4. 23:18
단위 테스트 스타일 출력 기반(output-based), 상태 기반(state-based), 통신 기반(communication-based)이라는 세 가지 테스트 스타일이 있다. 출력 기반 스타일의 테스트가 가장 품질이 좋고, 상태 기반 테스트는 두 번째로 좋은 선택이며, 통신 기반 테스트는 간헐적으로만 사용해야 한다. 안타깝게도 출력 기반 테스트 스타일은 아무데서나 사용할 수 없으며, 순수 함수 방식으로 작성된 코드에만 적용된다. 이를 위해 함수형 프로그래밍 원칙을 사용해 기반 코드가 함수형 아키텍처를 지향하게끔 재구성해야 한다. 출력 기반 스타일 public class PriceEngine { public decimal CalculateDiscount(params Product[] products) ..