-
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
[BE] refactor: 테스트 코드 리팩터링 #376
Conversation
d4a495e
to
749a4a1
Compare
backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java
Outdated
Show resolved
Hide resolved
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.
너무 고생하셨어요 👍
backend/src/test/java/com/funeat/acceptance/auth/AuthAcceptanceTest.java
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/member/MemberAcceptanceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/product/CategoryAcceptanceTest.java
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/acceptance/product/ProductAcceptanceTest.java
Outdated
Show resolved
Hide resolved
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.
너무너무 고생많으셨습니다 로건..........😭
짱짱맨
backend/src/test/java/com/funeat/review/application/ReviewServiceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java
Outdated
Show resolved
Hide resolved
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.
정말 힘든 작업... 고생했어요 😥
36시간의 사나이..
auth, member, product 위주로 확인했고, 몇 가지 코멘트 남겼습니다!
👍👍👍
backend/src/test/java/com/funeat/auth/application/AuthServiceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/member/application/MemberServiceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/member/application/MemberServiceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/member/application/MemberServiceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/product/application/ProductServiceTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/com/funeat/product/application/ProductServiceTest.java
Outdated
Show resolved
Hide resolved
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.
커밋 40개 미쳤다,,
정말 고생 많았어용
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.
고생하셨슴다,,,, 로건
Issue
✨ 구현한 기능
DatabaseCleaner
테스트 격리를 제대로 하지 않음[발견] : 일부 테스트에 있는
...ignoringFields("id")
을 제거한 테스트에서 테스트 실패 발생[AS-IS] :
DatabaseCleaner
가 각 테스트를 실행하기 전에id
값을1
로 초기화하지 않음[TO-BE] :
DatabaseCleaner
가 데이터를 제거할 뿐만 아니라id
값도1
로 초기화하도록 수정Fixture
추가이슈에서 언급했듯이
public static final MEMBER = new Member(...)
처럼 만들면 테스트 격리가 되지 않습니다.그래서
return new Member(...)
로 생성 메서드를 만들어서 테스트 격리가 되도록 만들었습니다.추가 리팩터링 진행하고, 실패 테스트 코드 추가했습니다
SoftAssertions
사용[이유] : 테스트를 실패할 때, 디버깅하기 편해집니다.
SoftAssertions
가 필요 없는 테스트들의 경우에는 통일성을 위해 적용했습니다.RepositoryTest
,ServiceTest
최상위 클래스 추가[이유 1] : 컨텍스트 캐싱 재사용으로 인한 테스트 속도 증가
[이유 2] : 편한 관리를 위함
Repository
의save()
,saveAll()
관련 변경 사항save()
,saveAll()
메서드 네이밍 변경save()
,saveAll()
을@@_추가_요청
이라 하기엔 실제 메서드 행동과 다릅니다.save()
→단일_@@_저장
,saveAll()
→복수_@@_저장
으로 통일AcceptanceTest
,ServiceTest
,RepositoryTest
로 이동단일_@@_저장
,복수_@@_저장
에 사용되고 있어서 중복 코드를 제거하기 위해 이동 했습니다.saveAll()
메서드에varargs
적용복수_@@_저장(...)
을 하려면List.of(...)
로 감싸서복수_@@_저장(List.of(...))
를 해야 됐습니다. 그래서 메인 테스트 메서드에List.of(...)
를 만드는 코드가 100줄이 넘어갔습니다. 여기서varargs
를 적용하여 자식 테스트 메서드 내부에서 리스트를 감싸주어 메인 테스트의 가독성을 높이게 만들었습니다.@Nested
적용하여 테스트 계층화[적용 방법] :
[메서드이름]_테스트
→필요하면 세부 내용으로 계층화
→성공_테스트
,실패_테스트
로 적용했습니다.[장점] : 테스트 가독성도 좋아지고, 유지보수하기 매우 편해집니다. 특히 누락된 케이스를 찾기 편해질 것으로 예상됩니다.
[단점] :
성공_테스트
,실패_테스트
가 서로 섞여서 수행되지 않아 한 메서드에 대한 랜덤한 테스트를 수행하기 힘들어졌습니다.기존에 카카오 로그인 부분을 테스트 할 수 없었는데, 생각해보니
TestPlatformUserProvider
로 PSA를 적용해서 테스트 가능했습니다.그래서 Mock 테스트를 제거하고, Classic 테스트로 변경했습니다.
이제 모든 테스트가 Classic 테스트입니다.
CategoryAcceptanceTest
,ProductAcceptanceTest
분리Steps
에 있는 요청 메서드를 전부 컨트롤러 메서드 순서대로 수정[이유] : 테스트 유지보수를 편하게 하기 위함
varargs
적용📢 논의하고 싶은 내용
테스트 삭제할만한 부분
통과하고_있다
라는 키워드로 만들었습니다. 억까 테스트가 좀 있을 수도 있어서 테스트 삭제할만한 부분은 리뷰로 알려주세요프로덕션 코드 논의할 부분들
ReviewFavorite
의createReviewFavoriteByMemberAndReview
를 그냥create
로 바꿔도 될 것 같습니다.ReviewFavorite
,member
,review
,favorite
을 엔티티와 파라미터만 봐도 무슨 일을 하는지 충분히 추론 가능합니다.TagType
에서PRICE
를 다른 이름으로 해야할 것 같아요. 갓성비 말고는 전부 양에 대한 평가입니다.🎸 기타
⏰ 일정