@SpringBootTest
- ApplicationContext에 모든 Bean들을 등록한다.
- 즉, SpringBoot 어플리케이션을 실행했을 때와 동일하게 컨테이너에 Bean을 등록하고 생성한다.
@DataJpaTest
- 기본적으로 ApplicationContext에 JPA에 필요한 설정들만 등록한다.
- ComponentScan을 하지 않으므로 @Component 빈들이 등록되지 않는다.
- 따라서 @Service가 붙은 것에 대해 @Authwired하지 못한다.
- @BeforeAll에서 xxService = new xxService(xxRepository)와 같이 해준다.
@SpringBootTest | @DataJpaTest 비교 : @DataJpaTest의 경우 @Component를 ApplicationContext에 등록하지 않아 테스트 실행 속도가 빨라진다.
'Spring Boot > testing' 카테고리의 다른 글
비동기 테스트 주의 사항 (0) | 2025.02.01 |
---|---|
테스트 픽스처(Test Fixture) (0) | 2025.02.01 |
@WebMvcTest - @EnableJpaAuditing 주의사항 (0) | 2024.12.04 |
RestController 단위 Testing (0) | 2024.11.13 |
Database Intrgration Testing (0) | 2024.11.12 |