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

Step3: 테스트를 통한 코드 보호 #838

Open
wants to merge 9 commits into
base: hanseu9839
Choose a base branch
from

Conversation

hanseu9839
Copy link

안녕하세요. 리뷰어님 항상 신경써주셔서 리뷰해주셔서 감사합니다.

궁금한 사항이 있어서 질문드립니다.

  1. 컨트롤러 서비스 테스트 메소드 이름이랑 서비스 테스트 코드 메소드 이름이랑 패턴이 비슷한데 해당 메소드 이름으로 지어도 괜찮을까요?

Copy link

@liquidjoo liquidjoo left a comment

Choose a reason for hiding this comment

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

안녕하세요 승균님
피드백 반영 및 미션 잘해주셨어요 👍
몇 가지 코멘트 남겼습니다
확인하고 다시 요청해 주세요 🙇

Comment on lines +87 to +104
- [ ] 주문 내역이 반드시 포함되어야 한다.
- [ ] 주문 내역은 최소 1개 이상의 주문 **항목(OrderLineItem)** 으로 구성된다.
- 각 주문 항목에 대해 다음 조건이 검증된다:
- [ ] 메뉴가 활성화 상태여야 한다.
- [ ] 주문 항목에 입력된 가격이 실제 메뉴 가격과 동일해야 한다.
- [ ] 주문 항목의 수량이 0 이상이어야 한다.
- 주문 생성 절차
- [ ] 주문이 정상적으로 생성되면, 주문 상태는 **WAITING(준비)** 으로 설정된다.
- [ ] 주문 생성 시간은 모든 검증이 완료된 후 자동으로 설정된다.

- **배달 (DELIVERY)**
- [ ] 배송지 주소가 반드시 입력되어야 한다.
- [ ] 입력된 배송지 주소가 유효한 경우에만 주문이 생성 가능하다.
- **포장 (TAKEOUT)**
- [ ] 배송지나 식사 테이블이 필요하지 않다.
- **매장 식사 (EAT_IN)**
- [ ] 유효한 식사 테이블이 할당되어 있어야 한다.
- [ ] 식사 테이블은 반드시 사용 가능한 상태여야 한다.

Choose a reason for hiding this comment

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

피드백 반영 좋습니다!!

Comment on lines +34 to +52
@Test
void 메뉴_그룹_생성_시_이름이_NULL이면_예외가_발생한다() {
// given
final MenuGroup request = menuGroup(null, null);

// when & then
assertThatIllegalArgumentException()
.isThrownBy(() -> menuGroupService.create(request));
}

@Test
void 메뉴_그룹_생성_시_이름이_빈_문자열이면_예외가_발생한다() {
// given
final MenuGroup request = menuGroup(null, "");

// when & then
assertThatIllegalArgumentException()
.isThrownBy(() -> menuGroupService.create(request));
}

Choose a reason for hiding this comment

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

예외 테스트 좋습니다 👍

Comment on lines 49 to 53
// then
assertThat(response.getName()).isEqualTo(request.getName());
assertThat(response.getPrice()).isEqualTo(request.getPrice());
assertThat(response.getMenuGroup().getId()).isEqualTo(request.getMenuGroupId());
assertThat(response.getMenuProducts()).hasSize(1);

Choose a reason for hiding this comment

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

assertAll 을 활용해도 좋습니다 :)
assertAll 과 assertThat 은 어떤 차이가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

assertAll 훨씬 더 좋을거 같습니다..! 중간에 실패했어도, 나머지가 실패했는지도 확인할 수 있어서 더 좋은거 같습니다.

List<Menu> response = menuService.findAll();

// then
assertThat(response).hasSize(2);

Choose a reason for hiding this comment

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

size 비교도 좋지만 기댓값과 예상값을 비교해보아도 좋을 것 같아요 :)

Copy link
Author

Choose a reason for hiding this comment

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

비교하려면 Equals , HashCode 구현해야해서, 사이즈로 해주었는데 Equals, HashCode 구현 후, 기댓값과 예상값 비교하면 될까요?

import static kitchenpos.fixture.MenuGroupFixture.menuGroup;
import static kitchenpos.fixture.MenuProductFixture.menuProduct;

public class MenuFixture {

Choose a reason for hiding this comment

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

Fixture 활용 좋습니다 👍

private MenuGroupService menuGroupService;

@Test
void 메뉴_그룹_생성_요청이_성공하면_메뉴_그룹정보를_반환한다() throws Exception {

Choose a reason for hiding this comment

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

지금은 서비스와 비슷한 이름을 갖고 있을 수 있습니다.
후에 더 나아가 서비스의 테스트가 완벽하다면 컨트롤러에선 어떤 것들을 검증하기 위해 테스트를 진행할까요?

Copy link
Author

Choose a reason for hiding this comment

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

요청 값이 들어오면 HTTP 상태 값만 검증하면 될거 같은데 아닐까요?

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(OrderRestController.class)
class OrderRestControllerTest {

Choose a reason for hiding this comment

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

꼼꼼한 테스트 좋습니다 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants