Skip to content

Conversation

@aegis1920
Copy link

안녕하세요 화투! 반갑습니다 :)
Mocking하지 않았으며 컨트롤러 통합테스트, 서비스 테스트, DAO 테스트를 진행했습니다.
프로덕션 코드를 수정하지 않고 기본 데이터는 그대로 테스트에 가져왔습니다. 프로덕션 코드를 수정하지 않고 최대한 테스트 격리를 하려고 truncate.sql을 만들어서 매번 삭제하고 데이터를 넣도록 했는데 이보다 더 깔끔하고 나은 방법이 있는지 모르겠네요ㅠ
더 좋은 방법이 있을까요? 조언해주시면 감사하겠습니다!

- rest assured 의존성 추가
- test용 application.properties 추가
- data.sql 추가
- schema.sql 추가
- data.sql에 orders 및 order_line_item 레코드 추가
- TestObjectUtils에 주문 항목 생성 및 주문 생성 추가
- ServiceTest로 공통로직 분리
- MenuServiceTest menuGroupId 수정
Copy link

@phs1116 phs1116 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 +31 to +37
@BeforeEach
void setUp() {
menuName = "후라이드+후라이드";
menuPrice = BigDecimal.valueOf(19000L);
menuGroupId = 1L;
menuProducts = Collections.singletonList(createMenuProduct(1L, 1L, 2L));
}
Copy link

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.

그러네요! 해당 변수가 다른 곳에서 수정되지도 않아서 바로 초기화했습니다 :)

Comment on lines +55 to +57
Menu menu = createMenu(menuName, menuPrice, menuGroupId, menuProducts);
Menu savedMenu = menuDao.save(menu);
Optional<Menu> foundMenu = menuDao.findById(savedMenu.getId());
Copy link

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.

초기 데이터를 활용한다면 초기 데이터에 대해 의존이 생겨서 위와 같이 작성했습니다! 좀 더 테스트가 격리되도록, 초기 데이터가 모두 없을 경우에도 진행되도록 하고 싶어서요 :) 화투님은 findById 메서드만 있도록 해서 관심사의 분리를 더 확실히 하고 싶은 이유로 피드백을 주신건가요??

@DisplayName("주문 항목 findAll - 성공")
@Test
void findAll() {
List<OrderLineItem> orderLineItems = orderLineItemDao.findAll();
Copy link

Choose a reason for hiding this comment

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

해당 클래스의 멤버인 orderLineItems랑 혼용될 수 있겠네요.
앞서 말씀드렸던 것 처럼 공통적인 변수 아니면 굳이 필드로 빼서 setUp으로 초기화하지 않아도 될 것 같아요. :)

Copy link
Author

Choose a reason for hiding this comment

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

수정했습니다 :)

@@ -0,0 +1,12 @@
SET REFERENTIAL_INTEGRITY FALSE;

TRUNCATE TABLE order_line_item RESTART IDENTITY;
Copy link

Choose a reason for hiding this comment

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

truncate를 통해 db 상태를 관리하는 방법 외엔 딱히 없는걸로 알아요. :)
그 외에는 mock을 통해 매 테스트마다 돌려줄 값을 모킹해주는 방법이 있겠네요.

Copy link
Author

Choose a reason for hiding this comment

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

조언 감사합니다! 👍


@DisplayName("주문 상태 수정")
@Test
void changeOrderStatus() {
Copy link

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.

넵 2단계 진행하면서 해보겠습니다 :)

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class OrderServiceTest extends ServiceTest {
Copy link

Choose a reason for hiding this comment

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

테스트 매우 꼼꼼하게 잘 작성하셨네요. 👍

@phs1116 phs1116 merged commit e5aaf4c into woowacourse:aegis1920 Oct 10, 2020
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