Skip to content
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

Refactor : Clothes 관련 테스트 코드 추가 및 리팩토링 #97

Merged
merged 7 commits into from
Jan 28, 2024

Conversation

kkmin223
Copy link
Collaborator

@kkmin223 kkmin223 commented Jan 23, 2024

변경 사항

  • 테스트 코드 추가 및 리팩토링하였습니다.

테스트 작성 시 주의사항

  • public 메소드는 테스트를 작성합니다.
  • private 메소드는 테스트를 작성하지 않고, 작성해야 할 것 같다면 해당 메소드를 클래스로 분리하는 것을 고려해야 합니다.
  • 테스트 한개에 하나의 주제로 테스트해야 합니다.
  • 테스트 환경의 독립성을 보장해야 합니다. -> 로그인한 유저를 가져오는 userService.getAuthenticatiedUser() 같은 경우 로그인 여부에 따라 결과가 달라집니다. 해당 메소드가 테스트하려는 메소드안에 있을 경우 테스트 환경을 제어할 수 없게되므로 파라미터로 분리하여 해당 메소드를 테스트할 환경의 독립성을 보장할 수 있습니다.
  • 테스트를 하기위한 메소드가 필요하다면 보수적으로 접근하여 만들어야 합니다. -> 생성자, ToString() 같은 객체가 가지고 있을법한 메소드 같은 일반적인 경우에만 만들도록 하는것이 권장됩니다.
  • 테스트 환경을 통합해야 합니다. -> 테스트 실행 시 환경을 통합해야 테스트 실행비용이 줄어들게 됩니다.
    • IntegrationTestSupport.class : 레퍼지토리 or 서비스 테스트 생성 시 공용으로 상속받는 클래스 -> 테스트 클래스의 설정이 다르면 클래스마다 스프링이 재실행되어서 이를 최소화하기 위해서 공용으로 사용합니다.
    • ControllerTestSupport.class : 컨트롤러 테스트 생성 시 공용으로 상속받는 클래스 -> 컨트롤러 테스트에서 필요한 Bean과 서비스를 Mock으로 설정하기 위해서 사용합니다.

변경 필요한 부분

  • 이미지 추가 API에 이미지 파일에 대한 검증이 들어가면 좋을 것 같습니다.

@Lechros Lechros changed the title Refactor : Clthoes 관련 테스트 코드 추가 및 리팩토링 Refactor : Clothes 관련 테스트 코드 추가 및 리팩토링 Jan 25, 2024
Copy link
Collaborator

@jinhoon227 jinhoon227 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

단위 테스트 확인했습니다!

@kkmin223 kkmin223 merged commit 08bdb29 into main Jan 28, 2024
1 check passed
@kkmin223 kkmin223 deleted the refactor/add-clothes-test branch January 28, 2024 13:55
}

@Operation(summary = "옷 ID로 조회", description = "옷 조회 API - 옷 ID로 조회")
@GetMapping("/{id}")
public ApiResponse<FindClothesRes> findClothesById(@PathVariable Long id) {
public ApiResponse<FindClothesRes> findClothesById(@PathVariable @Positive(message = "옷 ID는 양수여야 합니다.") Long id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: @Valid는 앞에, @positive는 뒤에 위치하는데 기준이 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

positive는 message가 있어서 뒤에 적었는데 특별한 기준은 없습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants