문서 테스트와 컨트롤러 테스트를 분리하고 싶습니다. #454
awesomeo184
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
문서 테스트의 DTO 검증 관련 이슈를 처리하다가 문서 테스트와 컨트롤러 테스트가 통합되어 있을 때의 문제점을 발견해 논의하고자 합니다.
컨트롤러 테스트와 문서 테스트를 통합하자고 했을 때 "관리 포인트가 늘기 때문"을 주 이유로 꼽았었는데요, 지금 다시 살펴보니 이 둘을 통합했을 때 문서 테스트의 가독성이 너무 떨어진다는 문제점을 인식했습니다.
현재 저희는 예외 관련 문서를 따로 제공하고 있지 않습니다. 하지만 문서 테스트에서는 예외 검증을 하고 있지요.
아래 코드를 봐주세요.
이름이 빈 문자열이거나 10자 초과일 때는 서비스, 정확히는 도메인에서 예외가 터집니다.
그런데 두 경우 모두 다음처럼
jobService
스텁에서 예외가 터지기만 하면 결과가 같습니다.그렇다면 이름이
빈 문자열
이거나10자 초과
하는 것이 과연 컨트롤러가 관심을 가져야할 일일까요? 단순히 서비스에서 BusinessException이 터지면 그에 맞는 응답을 주는게 컨트롤러의 관심사가 아닐까요?Request만 테스트 -> Valid를 안썼을 때 테스트가 성공하는 문제.
Valid는 애매 -> 서비스 DTO를 따로 만들어서 거기서 검증.
ControllerAdvice는 따로 테스트 -> Controller는 테스트하지 않음.
Beta Was this translation helpful? Give feedback.
All reactions