[4주차] RateLimit 적용 및 테스트 커버리지 개선#85
Conversation
|
@devops3199 안녕하세요 찬엽님 ~! 가장 먼저 4주차를 구현해주셨네요 ! 4주간 고생 많으셨습니다 👍🏿 |
| private SeatPersistenceAdapter seatPersistenceAdapter; | ||
|
|
||
| @InjectMocks | ||
| private CreateBookingService createBookingService; |
There was a problem hiding this comment.
테스트 대상을 SUT(System Under Test) 이라고 부르는데, 실무에서는 테스트 대상을 코드 내에서 빠르게 식별하기 위해서 sut 이라는 네이밍도 자주 사용합니다.
| .parameter(LocalDate.class) | ||
| .parameter(Set.class)) | ||
| .set("seats", Set.of(TheaterSeat.B1, TheaterSeat.C1, TheaterSeat.D1)) | ||
| .sample(); |
There was a problem hiding this comment.
Set.of(TheaterSeat.B1, TheaterSeat.C1, TheaterSeat.D1) 부분을 불연속적인 좌석 을 의미하는 변수로 추출하여 전달하면 유지보수성 및 가독성이 더 좋아질 것 같습니다.
|
|
||
| var result = searchMovieService.searchMovies(searchCommand); | ||
|
|
||
| assertEquals(10, result.size()); |
There was a problem hiding this comment.
10이라는 매직넘버를 상수로 관리하거나 지역 변수로 관리하면 중복을 없앨 수 있을 것 같습니다.
| } | ||
| }, Collections.singletonList(key)); | ||
|
|
||
| if (Boolean.FALSE.equals(allowed)) { |
|
|
||
| @Test | ||
| public void Rate_Limit_테스트() { | ||
| var bookingRequest = new CreateBookingRequest(1L, 2L, 5L, 1L, LocalDate.of(2025, 3, 1), List.of("C1", "C2")); |
There was a problem hiding this comment.
테스트 메서드 이름을 더 명확하게 작성하면 좋을 것 같아요 !
There was a problem hiding this comment.
public void Rate_Limit_유저_영화_시간표_상영관_per_1요청_5분_테스트()
위처럼 어떤 rate limit 테스트인지 명시적으로 수정했습니다!
| @SpringBootTest(classes = EmbeddedRedisConfig.class) | ||
| @TestPropertySource(properties = "spring.config.location = classpath:application-test.yml") | ||
| @Sql(scripts = "/booking-data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) | ||
| public class BookingControllerTest { |
There was a problem hiding this comment.
독립적인 환경을 잘 구성해서 진행해주셨네요 👍🏿
| blockedIps.put(clientIp, LocalDateTime.now()); | ||
| throw new RateLimitException(); | ||
| } | ||
|
|
|
@devops3199 님 너무 잘 구현해주셨습니다 :) 코드 깔끔하네요 💯 좋았던 점
아쉬웠던 점
리뷰 포인트 및 추가 질문에 대한 답변
사실 repository 테스트는 통합테스트가 있다면 굳이 필요할까라는 생각을 저도 갖고 있긴 합니다. 복잡한 쿼리 위주의 애플리케이션(e.g 통계 등)이라면 의미가 있을 수 있겠습니다. 그 외의 경우, 실무에서 일정 수치의 커버리지를 만족 시켜야 한다고 하면 작성을 해야겠죠. 혹은 해당 부분은 측정되지 않도록 제외시키는 등의 작업이 필요합니다. 도메인 로직에 대한 테스트는 중요합니다. |
|
@BAEKJungHo |
|
|
||
| @SpringBootTest(classes = EmbeddedRedisConfig.class) | ||
| @TestPropertySource(properties = "spring.config.location = classpath:application-test.yml") | ||
| public class SeatTest { |
There was a problem hiding this comment.
단위 테스트 잘 작성해주셨네요 👍🏿 단위 테스트의 경우에는 @SpringBootTest 가 필요 없을 것 같습니다 !
|
|
||
| @Test | ||
| public void 연속된_열_체크_테스트() { | ||
| var discontinuousSeats = Set.of(TheaterSeat.B1, TheaterSeat.C1, TheaterSeat.D1); |
There was a problem hiding this comment.
테스트 메서드를 한글로 해주셔서 가독성이 높아졌습니다. 다만 조금 더 구체적으로 작성하면 좋을 것 같아요.
- e.g 비연속적인 열이 주어지는 경우 예외가 발생한다
|
@devops3199 감사합니다 ㅎㅎ 4주간 고생 많으셨습니다 !! 💯 |
[4주차] RateLimit 적용 및 테스트 커버리지 개선
작업 내용
이번 주차에서 고민되었던 지점이나, 어려웠던 점을 알려 주세요.
리뷰 포인트
기타 질문