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

[BE] ScheduleRecommenderTest에서 잘못 작성된 테스트를 수정해요 :( #336

Open
2 tasks
hw0603 opened this issue Aug 26, 2024 · 0 comments
Open
2 tasks
Labels
🐈‍⬛ 백엔드 백엔드 관련 이슈에요 :) 🧪 테스트 테스트를 해요 :)

Comments

@hw0603
Copy link
Member

hw0603 commented Aug 26, 2024

이슈 요약

현재 TotalScheduleRecommenderTest 수행 시 @Transactional 어노테이션이 없으면 LazyInitializationException 이 발생합니다.
findAllByAttendeeIn() 메서드에서 Schedule을 조회할 때 프록시 객체로 가져오는데, 테스트 코드의 단언문이 트랜잭션 밖에 있으므로 attendee를 조회할 수 없기 때문입니다.

또한, @BeforeEach 로 정의된 setUp() 에서 테스트 데이터를 삽입하고 있는데, @Transactional 추가 시 데이터 삽입 로직과 테스트 로직이 동일한 트랜잭션으로 묶이게 됩니다. 이때 동일 트랜잭션이므로 JPA 캐시에서 가져온 ‘정확히 동일한’ 객체를 단순 비교하고 있어서 현재의 테스트가 통과하는데, 현재와 같은 테스트는 DB를 거치지 않으므로 신뢰할 수 없습니다.
실제로 데이터 삽입 이후 명시적으로 영속성 컨텍스트를 em.clear() 하게 되면 캐시 미스가 발생하고, 실제 DB조회가 일어날 때 값이 같은 새로운 객체가 만들어지므로 테스트에 실패하게 됩니다.

상세 작업 내용

  • 테스트 코드에서 @Transactional 어노테이션 제거 (가능할 경우)
  • 테스트 데이터의 동등성 비교 로직 수정 (메모리 주소가 아닌 값을 기준으로 검사)

레퍼런스

@hw0603 hw0603 added 🐈‍⬛ 백엔드 백엔드 관련 이슈에요 :) 🧪 테스트 테스트를 해요 :) labels Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐈‍⬛ 백엔드 백엔드 관련 이슈에요 :) 🧪 테스트 테스트를 해요 :)
Projects
Status: No status
Development

No branches or pull requests

1 participant