-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature25] 유닛 테스트 추가 #26
base: main
Are you sure you want to change the base?
Conversation
성공시 _photos LiveData가 업데이트 되는지 검증 실패시 _apiError LiveData가 업데이트 되는지 검증
), | ||
total = 10000, | ||
total_pages = 1000 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 작성해주신대로 ApiService를 Mock객체로 사용하여 Repository의 로직을 테스트하는 패턴은 많이 사용하긴 합니다.
하지만 이 패턴은 네트워크호출을 직접 수행하지 않기때문에, 별도로 추가한 interceptor들은 테스트를 할 수가 없는 단점이 있습니다.
interceptor들은 어떻게 테스트할 수 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interceptor는 MockWebServer를 사용하는 방법이 있습니다. MockWebServer는 테스트 환경에서 서버를 모킹하고, 원하는 응답을 반환시킬 수 있습니다. 이를 통해 실제 서버 없이 테스트할 수 있고, Intercepteor가 요청을 잘 변경하는지 확인할 수 있습니다.
|
||
coVerify { unsplashRepository.searchPhotos(query) } | ||
|
||
viewModel.apiError.removeObserver(observer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given-When-Then 패턴을 사용하셨으니, 주석으로 영역을 구분해주시면 코드를 읽을때 가독성이 좋아집니다~
혹은, println()으로 영역을 구분하면서,
- 어떤 준비과정이 있고(Given)
- 어떤 동작을 수행할 때(When)
- 어떤 결과가 있는지(Then)
써두면, 이 코드가 어떤 테스트인지를 좀 더 명확하게 파악하는데 도움이 됩니다!
요건 이번 PR에서 개선해주세요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 알겠습니다!
|
||
viewModel.searchPhotos(query) | ||
|
||
advanceUntilIdle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 어떤 역할을 하는 메서드인가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
advanceUntilIdle()
는 테스트 환경에서 코루틴의 실행을 끝까지 진행시키는 역할을 합니다.
테스트 코드에서 코루틴을 사용하면 코루틴이 비동기적으로 실행이 되어 즉시 완료되지 않을 수 있는데, advanceUntilIdle()
을 호출하면 현재 실행 중이거나 대기 중인 모든 코루틴이 완료될 때까지 실행을 진행해줍니다.
Quality Gate failedFailed conditions |
#️⃣연관된 이슈
#25
📝작업 내용
Given - When - Then 패턴을 사용하여