반응형

DataJpaTest를 연습중이다.

아래와 같이 진행하면 testRepository.save() 하면 실제로 쿼리를 실행시키지 않는다.

기본으론 내장 메모리로 하는 것 같다.

@RunWith(SpringRunner.class)
@DataJpaTest 

아래와 같이 추가해주면 쿼리가 실행되며 쿼리가 찍히는걸 확인 할수 있다.

@Transactional(propagation = Propagation.NOT_SUPPORTED)

 

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

 

46. Testing

A Spring Boot application is a Spring ApplicationContext, so nothing very special has to be done to test it beyond what you would normally do with a vanilla Spring context. By default, @SpringBootTest will not start a server. You can use the webEnvironment

docs.spring.io

찾아보니 기본적으로 data JPA 테스트는 트렌잭션과 롤백이 된다고 하고,

위에 설정을 통해 트랜젝션 비활성으로 설정이 된다고 나와 있다.

 

데이터가 영속성에 잘 들어갔는지 실제로 Assert로 데이터를 가져와서 확인을 할려면

EntityManager를 사용해서 확인하는데

@Transctional을 사용하면

@TestEntityManager는 접근이 안되고 @EntityManager로 접근해야한다.

 

반응형

+ Recent posts