Skip to content

[Mod] preparationUser api 테스트코드 작성 #121

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

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

jjjh02
Copy link
Contributor

@jjjh02 jjjh02 commented Feb 26, 2025

추가한 코드

  • 리팩토링 과정에서 통일한 getUserIdFromToken를 모두 userAuthService에서 불러오도록 수정
  • Controller 테스트 - API 응답을 검증하는 것이 목적 -> Mocking을 활용하여 ScheduleService의 의존성을 제거
  • Service 테스트 - 실제 데이터 저장 및 조회가 필요한 로직 -> DB를 사용하여 검증
  • Mockito.verify()를 활용하여 서비스 메서드가 기대한 횟수만큼 호출되었는지 검증
  • PreparationUserControllerTest 파일 설정을 위해 ControllerTestSupport 설정 추가

PreparationUserServiceTest 결과

image

PreparationUserControllerTest 결과

image

close #102

@jjjh02 jjjh02 linked an issue Feb 26, 2025 that may be closed by this pull request
preparationUser1Id, newUser, "세면", 10, preparationUser2));
preparationUserRepository.save(preparationUser1);
preparationUserRepository.save(preparationUser2);
preparationUserRepository.save(preparationUser3);
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분 중복코드로 보여지는데 이렇게 짜신 이유가 있을까요?
PreparationUser preparationUser3 = preparationUserRepository.save(new PreparationUser( preparationUser3Id, newUser, "화장", 10, null));
new를 통해 생성자로 객체 생성하고 바로 save()로 JPA에 저장하는 코드인데 바로 아래줄에
preparationUserRepository.save(preparationUser3);
위 코드로 save()로 반환받은 저장 객체를 다시 저장하신 이유가 궁금합니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

처음에는 객체를 생성한 후 별도로 저장하는 코드가 있었고, 이후에 save()를 즉시 호출하는 방식으로 변경했는데, 기존코드가 수정이 되지 않았네요. 다시 커밋했습니다.

UUID.randomUUID(), newUser, "알림확인", 10, preparationUser2));
preparationUserRepository.save(preparationUser1);
preparationUserRepository.save(preparationUser2);
preparationUserRepository.save(preparationUser3);
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분도 왜 동일한 객체를 두번 save()하는지 궁금합니다

@JunbeomKoreaUniv
Copy link
Contributor

Service 테스트 - 실제 데이터 저장 및 조회가 필요한 로직 -> 인메모리 DB(H2)를 사용하여 검증

H2를 사용하여 테스트 진행하셨다고 하셨는데 application.properties에서 DB연결하는 속성을 수정하셔서 하셨는지 아니면 테스트용 properties를 로컬에서 따로 만드셨는지 혹은 다른 방법으로 하셨는지 궁금합니다

@jjjh02
Copy link
Contributor Author

jjjh02 commented Feb 26, 2025

처음 의도는 H2를 사용하는거였는데 H2를 사용할시 수정해야할 부분이 많아져서 로컬 DB를 접근하는 방식으로 바뀌었는데 PR에 첫 의도대로 작성하게 되었네요. 수정하였습니다!

@JunbeomKoreaUniv
Copy link
Contributor

처음 의도는 H2를 사용하는거였는데 H2를 사용할시 수정해야할 부분이 많아져서 로컬 DB를 접근하는 방식으로 바뀌었는데 PR에 첫 의도대로 작성하게 되었네요. 수정하였습니다!

로컬로 세팅하신 MySQL 말씀하시는거죠?

@jjjh02
Copy link
Contributor Author

jjjh02 commented Feb 27, 2025

네 맞습니다!

@JunbeomKoreaUniv JunbeomKoreaUniv merged commit cc93408 into main Feb 27, 2025
1 of 2 checks passed
@JunbeomKoreaUniv JunbeomKoreaUniv deleted the test/preparationUser branch February 27, 2025 00:44
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.

preparationUser api 관련 테스트코드 작성
2 participants