목 테스트
-
엘레강트 오브젝트 : Mock 대신 Fake 사용책책책 책을 읽읍시다/프로그래밍 2023. 8. 4. 00:09
단위 테스트에서 Mock은 객체 의존 관계를 대신해주기 때문에 편리하다. 특히 repository에 의존하는 service나 domain을 테스트할 때 repository 의존성을 대신해주어 속도도 빠르고 복잡한 데이터를 조사할 필요도 없어진다. 하지만 과도하게 사용할 경우 테스트가 장황해지고 리팩터링 내성이 저하된다. Fake는 이런 문제를 해결해준다. 다음 자기 자신을 새로운 환율로 변환할 수 있는 Cash 클래스를 보자. public class Cash { private final Exchange exchange; private final int amount; public Cash(Exchange exchange, int amount) { this.exchange = exchange; this.am..