-
Notifications
You must be signed in to change notification settings - Fork 227
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
Step3 - 테스트를 통한 코드 보호 #855
base: wocks1123
Are you sure you want to change the base?
Conversation
- 테스트를 위한 Product 객체 생성 클래스 추가
- 테스트를 위한 MenuGroup 객체 생성 클래스 추가
- fixture 사용, db 데이터 저장 후 테스트
통합테스트가 리팩토링 시 테스트 코드 변경을 대체로 줄일 수 있겠지만 항상 그런 것은 아닌 것 같습니다.
재찬님이 말씀하신 부분은 개발자라면 누구나 고민하게 되는 현실적이면서 중요한 문제인 것 같습니다. |
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.
바쁘신데 늦은 시간까지 미션진행하시느라 너무 고생하셨습니다! 👍
테스트 코드도 잘 작성해 주셨네요! 💯
그럼 리뷰 확인 부탁드립니다~ 🙏
|
||
@Test | ||
@DisplayName("메뉴를 등록한다.") | ||
void registerMenu() { |
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.
요구 사항을 다시 읽어보면 메뉴 등록이나 가격변경시 몇가지 실패케이스에 대한 테스트가 누락된게 보이네요?
메뉴의 가격은 지정한 상품들의 가격 총합보다 작아야 한다.
테스트 코드 작성하시면서 요구 사항의 [ ]
체크박스를 [x]
로 하나씩 표시하시면 놓치지 않으실 것 같아요.
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.
혹시 메뉴의 숨김이나 표시관련 기능의 테스트는 필요 없을까요? 🤔
- 지정한 메뉴를 노출한다.
- 지정한 메뉴를 숨김처리한다.
@Autowired | ||
private MenuGroupRepository menuGroupRepository; | ||
|
||
@Nested |
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.
@Nested
를 사용하여 테스트 케이스를 그륩화하니 한결 보기 좋은 것 같아요! 👍
MenuGroup menuGroup1 = MenuGroupFixture.createMenuGroup("한마리메뉴"); | ||
MenuGroup menuGroup2 = MenuGroupFixture.createMenuGroup("두마리메뉴"); |
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.
테스트 코드의 변수명에 넘버링보다 한글변수명등을 사용하면 직관적이 되어 가독성이 향상될 수 도 있어요. 😄
MenuGroup menuGroup1 = MenuGroupFixture.createMenuGroup("한마리메뉴"); | |
MenuGroup menuGroup2 = MenuGroupFixture.createMenuGroup("두마리메뉴"); | |
MenuGroup 한마리_메뉴그룹 = MenuGroupFixture.createMenuGroup("한마리메뉴"); | |
MenuGroup 두마리_메뉴그룹 = MenuGroupFixture.createMenuGroup("두마리메뉴"); |
private MenuGroupService menuGroupService; | ||
|
||
@Autowired | ||
private MenuGroupRepository menuGroupRepository; |
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.
혹시 조금 여유가 되신다면 필수는 아니나 수업시간에 배우신 Fake객체로 Repository를 대체하면
어떤 이점이 있는지 직접 체감해 보시는 것도 좋을 것 같아요. 😄
안녕하세요! 늦었지만 PR 드립니다.
서비스 클래스에 대한 단위테스트를 작성할까 고민하다가 통합테스트를 작성했습니다. 나중에 리팩토링을 진행하면 서비스 코드가 많이 변경될텐데 통합테스트로 구현하면 테스트 코드 수정이 비교적 적지 않을까 생각했습니다. Order 관련 테스트 코드는 분량이 많아 작업중입니다.
이번 과제 수행중 궁금한 내용은 테스트 데이터 초기화입니다. 테스트 메서드 시작전에 repository를 사용해 DB에 데이터를 추가했는데, 테스트 종료 후
menuRepository.deleteAll()
을 호출하면 MenuProduct와 외래키 제약때문에 오류가 발생했습니다. repository로 delete를 호출하지 않는 방식을 생각해봤습니다.@Transactional
을 붙이면 메서드 종료 후 롤백을 수행하지만, 트랜잭션 범위를 테스트 메서드까지 확장하는건 적절하지 않은 방식 같습니다.지금은 관리해야할 내용이 추가되더라도 테스트용 SQL 파일을 추가하는게 맞지 않을까 생각중입니다. 연관관계가 복잡한 테스트 데이터가 필요할 때 어떻게 관리할 수 있을지 질문드립니다.
감사합니다!