Skip to content

[TEST] 메뉴 폴더 테스트#76

Merged
You-Hyuk merged 12 commits into
developfrom
KAN-36-test/menu-folder
Apr 10, 2025
Merged

[TEST] 메뉴 폴더 테스트#76
You-Hyuk merged 12 commits into
developfrom
KAN-36-test/menu-folder

Conversation

@david-parkk
Copy link
Copy Markdown
Member

✏️ 작업 개요

⛳ 작업 분류

  • 테스트 환경 설정
  • 메뉴 폴더 테스트

🔨 작업 상세 내용

  1. 테스트 환경 설정(DB Cleaner)을 추가하였습니다. 각 테스트 마다 데이터를 truncate합니다
  2. 메뉴 폴더 테스트를 작성하였습니다.
  3. TestData 클래스들을 선언하여 사전 데이터 구성을 지원합니다.
  4. 통합 테스트를 작성하였습니다.

💡 생각해볼 문제

  • 첫 테스트 코드인 만큼 생각해봐야 할 내용이 많습니다.
  • DB Cleaner의 경우 다양한 방법이 있습니다.
  • 가장 중요하게 생각하는 것은 테스트 코드로 인해 프로덕트 코드가 변경되지 않는 것입니다.(코드가 추가된 부분이 있습니다)
  • 통합 테스트 VS 단위 테스트 등등...

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 4, 2025

Test Results

9 tests   9 ✅  3s ⏱️
2 suites  0 💤
2 files    0 ❌

Results for commit 1eab0e8.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

@You-Hyuk You-Hyuk left a comment

Choose a reason for hiding this comment

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

확실히 단위 테스트가 아닌 통합 테스트를 진행하다 보니 하나의 테스트 코드 메소드의 then에 해당하는 검증 부분이 많이 길어지긴 하는 것 같습니다... 또한 테스트 코드를 작성하며 기존 프로덕트 코드를 수정하는 경우는 테스트를 진행하며 로직 상 고쳐야 할 부분이 있는 경우가 아니면 지양하는 것이 좋을 것 같아요.
테스트 코드를 작성해 본 경험이 없다보니 DBCleaner와 같은 환경 설정은 처음 보기도 하고 리뷰를 하는데 부족한 점이 있을 것 같습니다만 궁금한 부분 리뷰 달아놓았으니 확인해주시면 감사하겠습니다! 수고하셨어요 👍 👍

Comment on lines +10 to +25
@TestConfiguration
public class MenuTestConfig {

@Autowired
EntityManager entityManager;

@Bean
public UserTestData userTestData() {
return new UserTestData(entityManager);
}

@Bean
public MenuTestData menuTestData() {
return new MenuTestData(entityManager);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TestData가 중복되는 경우도 있을 것 같은데 domain/menu/data 패키지로 구분하신 것은 각각의 도메인마다 TestData를 작성하면 되는 걸까요??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

테스트 데이터는 엔티티 레벨에서 데이터를 생성하여 저장하도록 구성하였습니다. 최대한 테스트 코드의 가독성을 높이기 위한 목적으로 분리하였어요

TestData가 중복되는 경우도 있을 것 같은데 domain/menu/data 패키지로 구분하신 것은 각각의 도메인마다 TestData를 작성하면 되는 걸까요??

제 의도는 이해하신거 같고, 의논이 필요한 부분이라 의견 주시면 수용하겠습니다!

Comment on lines +57 to +60
entityManager.persist(menuFolder1);
entityManager.persist(menuFolder2);
entityManager.persist(menuFolder3);
return menuFolderList;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

createTestMenuFolder 메소드에서는 flush를 사용하셨는데, 해당 메소드에서는 사용하지 않은 이유가 있을까요? Transactional 어노테이션이 있어서 문제는 없을 것 같지만 여쭤봅니다! 그리고 생성한 메뉴폴더들을 List에 담지 않고 반환하고 있는데 의도하신 것일까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

수정 하였습니다

@PersistenceContext
private EntityManager entityManager;

@SuppressWarnings("unchecked")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

해당 어노테이션은 어떤 기능을 가지고 있나요??

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

이전 코드에서 테이블 이름을 object으로 받은뒤 선언적 형변환을 통해 String으로 변환 코드에 발생할 수 있는 unchecked warning을 삭제하고자 선언하였는데 현재는 필요 없는 코드입니다.

Comment on lines +61 to +77
@Test
void 메뉴판을_저장_할_수_있다() {
//given
String menuFolderTitle = "메뉴판 제목";
SaveMenuFolderRequest saveMenuFolderRequest = new SaveMenuFolderRequest(null, menuFolderTitle,
MenuFolderIcon.ANGRY,
Collections.emptyList());
CustomUserDetails testCustomUserDetails = userTestData.createTestEmailUser();

//when
ApiResponse<SaveMenuFolderResponse> response = menuFolderController.saveMenuFolder(
saveMenuFolderRequest, testCustomUserDetails);

//then
Assertions.assertThat(response.isSuccess()).isEqualTo(true);
Assertions.assertThat(response.getResponse().getMenuFolderTitle()).isEqualTo(menuFolderTitle);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

대부분의 경우 when에서 컨트롤러 메소드를 호출해 Response를 생성하고 then에서 response의 값으로 검증을 하는 흐름으로 이해했는데 맞을까요?

@You-Hyuk You-Hyuk merged commit 6a73094 into develop Apr 10, 2025
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