-
Notifications
You must be signed in to change notification settings - Fork 2
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] test: 객관식 검증, 리뷰 생성 테스트에 픽스처를 적용 #552
[BE] test: 객관식 검증, 리뷰 생성 테스트에 픽스처를 적용 #552
Conversation
Test Results82 tests 82 ✅ 3s ⏱️ Results for commit 5b2c76e. ♻️ This comment has been updated with latest results. |
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.
커커커커커비 수고했어요 ㅎㅎ
import reviewme.question.domain.Question; | ||
import reviewme.question.domain.QuestionType; | ||
|
||
@Component |
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.
커비는 픽스쳐를 빈으로 등록했고, 디스코드에 그 이유를 이렇게 적어줬어요.
매 테스트 클래스마다 픽스처 객체를 새로 생성해줄 필요가 없음
쓰이는 곳이 서비스 테스트니까 어차피 컨테이너가 뜸
그런데 모든 픽스쳐가 '테스트 클래스마다 픽스처 객체를 새로 생성해줄 필요가 없음'에 해당되는 것은 아니라 생각해요. 예를 들어 section 은 List questionIds 를 받아야 하는 등, 동적으로 생성해줘야 하는 픽스쳐들이 있어요. 그래서 매번 새롭게 객체를 만들어주도록 함수로 픽스쳐를 만들 수 있도록를 구성했던 것이에요.
그래서 픽스쳐를 빈으로 등록할 필요는 없고, 여러 곳에서 쓰일 수 있게 저는 static을 붙였어요 ㅎㅎ 혹시 이런 생각에 대해서는 어떻게 생각하는지 커비의 의견을 듣고 싶어요!
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.
왜 static을 생각 못했죠...? ㅎㅎ static이 딱 필요한 순간이었다고 생각합니다! 반영 완료!
|
||
@Test | ||
void 저장되지_않은_질문에_대한_응답이면_예외가_발생한다() { | ||
// given | ||
questionRepository.save(questionFixture.선택형_필수_질문()); |
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.
없어도 통과하는 것 맞네요ㅎㅎ 반영 완료!
CreateReviewAnswerRequest request = new CreateReviewAnswerRequest( | ||
savedQuestion.getId(), List.of(1L), null | ||
); |
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.
이 부분도 바로 윗 테스트 코드처럼 long notSavedOptionId = 1L;
으로 변수명으로 추출하면 더 가독성있을 것 같아요
@@ -101,6 +102,7 @@ void setUp() { | |||
@Test | |||
void 옵션그룹에서_제공하지_않은_옵션아이템을_응답하면_예외가_발생한다() { | |||
// given | |||
Question savedQuestion = questionRepository.save(questionFixture.선택형_필수_질문()); | |||
OptionGroup savedOptionGroup = optionGroupRepository.save( |
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.
106 ~ 114 라인도 그 객체의 내용이 중요한 것이 아니니 픽스쳐로 바꿀 수 있을 것 같은데, 내키지 않으면 안하셔도 됩니당!
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.
크게 변한 내용은 Fixture 말고는 없어 Approve합니다, 만약 static PR이 먼저 올라오고 머지되야 한다면 rebase + force push 해주세요~~ 👍🏻
52e67bf
to
5b2c76e
Compare
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.
어프푸푸푸푸푸뤂!!🐠
CreateReviewAnswerRequest request = new CreateReviewAnswerRequest( | ||
savedQuestion.getId(), List.of(1L), null | ||
savedQuestion.getId(), List.of(notselectedOptionId), null |
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.
구구구구구굳
Question savedQuestion = questionRepository.save(선택형_필수_질문()); | ||
OptionGroup savedOptionGroup = optionGroupRepository.save(OptionGroupFixture.선택지_그룹(savedQuestion.getId())); | ||
OptionItem savedOptionItem = optionItemRepository.save(OptionItemFixture.선택지(savedOptionGroup.getId())); |
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.
확실히 깔끔 하네요 👍👍
특이사항 없어서 바로 어프룹 흡니다
🚀 어떤 기능을 구현했나요 ?
🔥 어떻게 해결했나요 ?
fixture를 컴포넌트로 등록해서 사용했습니다.📝 어떤 부분에 집중해서 리뷰해야 할까요?
📚 참고 자료, 할 말