-
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] 테스트를 통한 코드 보호 #849
base: mkkim90
Are you sure you want to change the base?
Conversation
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.
민균님 테스트 코드 꼼꼼하게 잘 작성해주셨습니다. 👍
조금만 수정해주시면 될 것 같아요 🔥
확인 부탁 드립니다.
@ParameterizedTest | ||
@NullAndEmptySource | ||
fun `메뉴 그룹명이 없을 경우 예외 발생`(input: String?) { |
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.
annotation 활용 👍
@Test | ||
fun `메뉴 그룹 생성`() { | ||
// given | ||
val menuGroup = randomMenuGroup() | ||
every { menuGroupRepository.save(any()) } returns menuGroup | ||
|
||
// when | ||
menuGroupService.create(menuGroup) | ||
|
||
// then | ||
verify { menuGroupRepository.save(any()) } | ||
} |
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.
given when then 패턴 주석 👍
menuService = MenuService(menuRepository, menuGroupRepository, productRepository, purgomalumClient) | ||
} | ||
|
||
@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 활용 너무 잘 해주셨습니다 👍
} | ||
|
||
@Nested | ||
inner class `메뉴 생성시` { |
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.
전반적으로 테스트를 조건을 모두 체크해서 꼼꼼하게 작성해주셨는데요
정상 실행을 확인할 수 있는 테스트 코드도 추가해주시면 좋을 것 같아요
정상적으로 실행이 됬을때 확인해야하는 값이 모두 정상으로 바뀐것을 확인해주시고
메뉴 생성시 가격은 0보다 커야 한다는 조건이므로 경계값인 0을 포함해서 작성해주시면 좋을것 같습니다.
every { menuGroupRepository.findById(menu.menuGroupId) } returns Optional.of(menu.menuGroup) | ||
every { productRepository.findAllByIdIn(menuProducts.map(MenuProduct::getProductId)) } returns emptyList() |
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.
테스트를 mock을 이용해서 해주셨는데
기회가 되신다면 저번주 강의 초반부에 제이슨님께서 설명해주신 in-memory 방식의 repositoy 방식을 한번 권해드립니다. 클래스를 추가로 작성해야 한다는 점은 있지만 해당 repository로 입력한 값을 직접 제어할 수 있다는 점의 장점이 있습니다.
키친포스를 리팩토링 하게되는 시점에서 테스트도 변경이 필요하게 되므로 그때 한번 해보시면 좋을 것 같아요 😄
@Test | ||
fun `손님 수는 0으로 초기 설정, 자리 상태는 비움으로 초기 설정한다`() { | ||
// given | ||
val orderTable = randomOrderTable() | ||
every { orderTableRepository.save(any()) } returns randomOrderTable(numberOfGuests = 0, occupied = false) | ||
// when then | ||
orderTableService.create(orderTable).run { | ||
this.numberOfGuests shouldBe 0 | ||
this.isOccupied shouldBe false | ||
} | ||
} |
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 | ||
inner class `상품 생성시` { | ||
@Test | ||
fun `가격이 널인 경우 예외 발생`() { |
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.
테스트 에서도 널이라는 표현보다는 다르게 작성해주시면 어떨까요? 😄
성태님, 안녕하세요. 늦었지만 STEP3 테스트 통한 코드 보호 미션 완료하였습니다.
mockk 을 활용하여 단위테스트 코드를 작성하였습니다.
작성한 요구사항을 체크해가면서 테스트 코드를 작성하였습니다.
코드가 많긴하지만 커밋별로 분리하여 작업하였습니다. 해당 목록 별로 보시면 좀 더 수월하실 듯합니다.