Spring Boot/testing
통합 테스트 @SpringBootTest vs @DataJpaTest
최-코드
2025. 2. 1. 11:15
@SpringBootTest
- ApplicationContext에 모든 Bean들을 등록한다.
- 즉, SpringBoot 어플리케이션을 실행했을 때와 동일하게 컨테이너에 Bean을 등록하고 생성한다.
@DataJpaTest
- 기본적으로 ApplicationContext에 JPA에 필요한 설정들만 등록한다.
- ComponentScan을 하지 않으므로 @Component 빈들이 등록되지 않는다.
- 따라서 @Service가 붙은 것에 대해 @Authwired하지 못한다.
- @BeforeAll에서 xxService = new xxService(xxRepository)와 같이 해준다.
@SpringBootTest | @DataJpaTest 비교 : @DataJpaTest의 경우 @Component를 ApplicationContext에 등록하지 않아 테스트 실행 속도가 빨라진다.