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

[BE] refactor: 테스트 코드 리팩터링 #376

Merged
merged 41 commits into from
Aug 11, 2023
Merged

[BE] refactor: 테스트 코드 리팩터링 #376

merged 41 commits into from
Aug 11, 2023

Conversation

70825
Copy link
Member

@70825 70825 commented Aug 9, 2023

Issue

✨ 구현한 기능


  1. 🐛 DatabaseCleaner 테스트 격리를 제대로 하지 않음
    [발견] : 일부 테스트에 있는 ...ignoringFields("id")을 제거한 테스트에서 테스트 실패 발생
    [AS-IS] : DatabaseCleaner가 각 테스트를 실행하기 전에 id값을 1로 초기화하지 않음
    [TO-BE] : DatabaseCleaner가 데이터를 제거할 뿐만 아니라 id값도1로 초기화하도록 수정

  1. Fixture 추가
    이슈에서 언급했듯이 public static final MEMBER = new Member(...)처럼 만들면 테스트 격리가 되지 않습니다.
    그래서 return new Member(...)로 생성 메서드를 만들어서 테스트 격리가 되도록 만들었습니다.

  1. ✨ 다양한 경우의 성공 테스트, 누락된 성공 테스트 추가

  1. 🔧 레시피 테스트 코드 리팩터링
    추가 리팩터링 진행하고, 실패 테스트 코드 추가했습니다

  1. 🔧 하나의 테스트에 2개 이상의 검증이 필요하면 SoftAssertions 사용
    [이유] : 테스트를 실패할 때, 디버깅하기 편해집니다. SoftAssertions가 필요 없는 테스트들의 경우에는 통일성을 위해 적용했습니다.

  1. 🔧 리포지토리 테스트, 서비스 테스트에RepositoryTest, ServiceTest 최상위 클래스 추가
    [이유 1] : 컨텍스트 캐싱 재사용으로 인한 테스트 속도 증가
    [이유 2] : 편한 관리를 위함

  1. 🔧 Repositorysave(), saveAll() 관련 변경 사항
  • [7-1] save(), saveAll() 메서드 네이밍 변경
    • [이유] : save(),saveAll()@@_추가_요청이라 하기엔 실제 메서드 행동과 다릅니다.
    • [변경] : save()단일_@@_저장, saveAll()복수_@@_저장으로 통일
  • [7-2] AcceptanceTest, ServiceTest, RepositoryTest로 이동
    • [이유] : 100줄이 넘는 코드가 단일_@@_저장, 복수_@@_저장에 사용되고 있어서 중복 코드를 제거하기 위해 이동 했습니다.
  • [7-3] saveAll() 메서드에 varargs 적용
    • [이유] : 복수_@@_저장(...)을 하려면 List.of(...)로 감싸서 복수_@@_저장(List.of(...))를 해야 됐습니다. 그래서 메인 테스트 메서드에 List.of(...)를 만드는 코드가 100줄이 넘어갔습니다. 여기서 varargs를 적용하여 자식 테스트 메서드 내부에서 리스트를 감싸주어 메인 테스트의 가독성을 높이게 만들었습니다.

  1. 🔧 @Nested 적용하여 테스트 계층화
    [적용 방법] : [메서드이름]_테스트필요하면 세부 내용으로 계층화성공_테스트, 실패_테스트로 적용했습니다.
    [장점] : 테스트 가독성도 좋아지고, 유지보수하기 매우 편해집니다. 특히 누락된 케이스를 찾기 편해질 것으로 예상됩니다.
    [단점] : 성공_테스트, 실패_테스트가 서로 섞여서 수행되지 않아 한 메서드에 대한 랜덤한 테스트를 수행하기 힘들어졌습니다.

  1. 🔧 Mock 테스트 제거
    기존에 카카오 로그인 부분을 테스트 할 수 없었는데, 생각해보니 TestPlatformUserProvider로 PSA를 적용해서 테스트 가능했습니다.
    그래서 Mock 테스트를 제거하고, Classic 테스트로 변경했습니다.
    이제 모든 테스트가 Classic 테스트입니다.

  1. 🔧 CategoryAcceptanceTest, ProductAcceptanceTest 분리
  • [이유] : 프로덕션 코드는 분리했는데, 테스트 코드는 분리가 안되어 있어서 분리했습니다.

  1. 🔧 Steps에 있는 요청 메서드를 전부 컨트롤러 메서드 순서대로 수정
    [이유] : 테스트 유지보수를 편하게 하기 위함

  1. 🔧 그 외 테스트 코드 리팩터링
  • 중복 메서드 제거, 가독성을 위해 자식 메서드 추가, 일부 자식 메서드에 varargs 적용

📢 논의하고 싶은 내용

테스트 삭제할만한 부분

  • 통과하고_있다라는 키워드로 만들었습니다. 억까 테스트가 좀 있을 수도 있어서 테스트 삭제할만한 부분은 리뷰로 알려주세요

프로덕션 코드 논의할 부분들

  • ReviewFavoritecreateReviewFavoriteByMemberAndReview를 그냥 create로 바꿔도 될 것 같습니다.
    • 이유 : ReviewFavorite, member, review, favorite을 엔티티와 파라미터만 봐도 무슨 일을 하는지 충분히 추론 가능합니다.
  • TagType에서 PRICE를 다른 이름으로 해야할 것 같아요. 갓성비 말고는 전부 양에 대한 평가입니다.
    • 갓성비, 푸짐해요, 배고파요, 적당해요

🎸 기타

  • 모든 테스트 코드를 수정했기 때문에 각자 리뷰 범위를 나눠서 진행하는게 좋아보입니다.

⏰ 일정

  • 추정 시간 : 12
  • 걸린 시간 : 36

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Unit Test Results

107 tests   107 ✔️  10s ⏱️
  68 suites      0 💤
  68 files        0

Results for commit 6dfbe04.

♻️ This comment has been updated with latest results.

@70825 70825 force-pushed the feat/issue-343 branch 2 times, most recently from d4a495e to 749a4a1 Compare August 9, 2023 16:30
Copy link
Collaborator

@wugawuga wugawuga left a comment

Choose a reason for hiding this comment

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

너무 고생하셨어요 👍

Copy link
Collaborator

@hanueleee hanueleee left a comment

Choose a reason for hiding this comment

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

너무너무 고생많으셨습니다 로건..........😭
짱짱맨

Copy link
Collaborator

@Go-Jaecheol Go-Jaecheol left a comment

Choose a reason for hiding this comment

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

정말 힘든 작업... 고생했어요 😥
36시간의 사나이..

auth, member, product 위주로 확인했고, 몇 가지 코멘트 남겼습니다!
👍👍👍

Copy link
Collaborator

@Go-Jaecheol Go-Jaecheol left a comment

Choose a reason for hiding this comment

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

커밋 40개 미쳤다,,
정말 고생 많았어용

@wugawuga wugawuga self-requested a review August 11, 2023 09:05
Copy link
Collaborator

@hanueleee hanueleee left a comment

Choose a reason for hiding this comment

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

대 로 건 선 생 님

Copy link
Collaborator

@wugawuga wugawuga left a comment

Choose a reason for hiding this comment

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

고생하셨슴다,,,, 로건

@70825 70825 merged commit d96bb60 into develop Aug 11, 2023
@70825 70825 deleted the feat/issue-343 branch August 11, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BE] 테스트 코드 리팩터링
4 participants