Skip to content

Conversation

@gmltn9233
Copy link
Contributor

🔧연결된 이슈

🛠️작업 내용

  • 테스트 코드에 필요한 더미데이터를 추가함
    image

🤷‍♂️PR이 필요한 이유

  • 이전 InitData 리팩토링으로 인해 DB의 테스트 데이터를 참조하던 테스트 코드가 작동하지 않는 문제가 발생하여, 테스트 코드에 맞는 더미데이터를 추가하여 테스트 코드를 리팩토링하였습니다.
  • 기존 DB에 의존하는 통합 테스트 방식에서 유닛 테스트 방식으로 리팩토링을 진행하려고 고민해보았으나, 서비스 로직이나 흐름을 테스트할때는 불가피하게 통합 테스트를 사용해야 한다고 결론지었습니다. (Mock 객체가 의도된 결과만 나오도록 설계한다면 서비스 테스트의 목적에 맞지 않다고 생각하였습니다.) 기존 로직이 DB에 의존을 많이하는 관계로, 현재로선 유닛 테스트로의 전환이 어렵다고 생각을 하는데 이에 대한 의견 부탁드리겠습니다!

✔️PR 체크리스트

  • 필요한 테스트를 작성했는가?
  • 다른 코드를 깨뜨리지 않았는가?
  • 연결된 이슈 외에 다른 이슈를 해결한 코드가 담겨있는가?

이전 Initdata 형식의 가상 데이터 추가함
@gmltn9233 gmltn9233 linked an issue Sep 9, 2024 that may be closed by this pull request
@gmltn9233 gmltn9233 changed the base branch from main to develop September 9, 2024 09:31
@whxogus215
Copy link
Contributor

유닛 테스트의 전환은 결국 기존의 설계 방식을 바꿔야 하는 문제로 이어진다고 생각합니다. 여기엔 많은 시간이 발생할 것이기에 서비스가 돌아감에 있어서는 현재로서는 문제가 발생하지 않기 때문에 지금 상태로 유지하고, 최대한 빠르게 오픈하는게 좋을 것 같아요.

@gmltn9233
Copy link
Contributor Author

유닛 테스트의 전환은 결국 기존의 설계 방식을 바꿔야 하는 문제로 이어진다고 생각합니다. 여기엔 많은 시간이 발생할 것이기에 서비스가 돌아감에 있어서는 현재로서는 문제가 발생하지 않기 때문에 지금 상태로 유지하고, 최대한 빠르게 오픈하는게 좋을 것 같아요.

동의합니다 !!

CompletedCoursesDomain data1 =
CompletedCoursesDomain.builder().
userDomain(userDao.findByStudentId(19011684L).get()).
userDomain(userDao.findByStudentId(19111111L).get()).
Copy link
Contributor

Choose a reason for hiding this comment

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

19111111 학번은 해당 테스트 코드에서만 사용되는 학번인건가요??

Copy link
Contributor Author

@gmltn9233 gmltn9233 Sep 10, 2024

Choose a reason for hiding this comment

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

넵 해당 테스트 코드가 실행될때 해당 학번을 가진 유저가 생성되고 종료되면 삭제됩니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

아하 클래스 레벨에 @Transactional 덕분에 나중에 롤백되는건가요?

Copy link
Contributor Author

@gmltn9233 gmltn9233 Sep 10, 2024

Choose a reason for hiding this comment

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

아하 클래스 레벨에 @Transactional 덕분에 나중에 롤백되는건가요?

그렇습니다. 이전에 InitData에 Test에 필요한 DB 데이터를 미리 입력해 놓았다면, 리팩토링 후 @Transactional 을 통해 테스트 코드마다 필요한 데이터를 테스트 레벨에서만 존재하도록 수정하였습니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

오오 그러면 굳이 별도의 test DB를 쓰지 않아도 되겠네요! 테스트 방법 배워갑니다~ ㅎㅎ

@gmltn9233 gmltn9233 merged commit 678273b into develop Sep 11, 2024
@gmltn9233 gmltn9233 deleted the fix-테스트-코드-리팩토링 branch September 23, 2024 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 테스트 코드 리팩토링

3 participants