새 Spring Boot 1.4 기능으로 코드를 업데이트하고 통합 테스트에서 새로운 @DataJpaTest
주석을 사용하려고했습니다. 실행하고 싶은 .sql 파일에 문제가 있습니다. 일부는 통합 테스트 용이고 다른 하나는 향후 프로덕션 데이터베이스 용입니다.spring-boot 1.4의 새로운 @DataJpaTest 및 application.properties와의 관계
내 통합 테스트에서는 /src/test/resources
디렉토리의 .sql 파일과 H2 용 메모리 내장 데이터베이스를 사용하여 @Sql
주석을 사용하고 있습니다. 생산을 위해 나는 mysql 데이터베이스를 사용하고 있으며, data-mysql.sql
파일을 /src/main/resources
안에 넣었다.
통합 테스트를 실행할 때 /src/test/resources
내부의 파일 만 실행되기를 원했지만 심지어 data-mysql.sql
도 실행 중입니다.
정상적인 동작입니까? 이걸 간단하게 바꿀 수 있습니까?
샘플 코드 : 어떤 도움
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.datasource.url=jdbc:mysql://localhost/prod
spring.datasource.username=root
spring.datasource.password=***
spring.datasource.initialize=true
spring.datasource.platform=mysql
감사 :
@RunWith(SpringRunner.class)
@DataJpaTest
@Sql("/test-data.sql")
public class CdrIntegrationTest {
// any tests here
}
그리고 내 "생산"CONFIGS이 그들이다.
예, 프로덕션 구성은 application.properties 파일에 있습니다. 내가 이해할 수없는 것은 그것이 왜 H2 데이터베이스 테스트를 위해로드되는 경우 데이터 mysql.sql 파일을로드하는 것인가? spring.datasource.platform 옵션 때문이라면 제거하되 데이터 - mysql.sql은 통합 테스트 또는 애플리케이션 시작에서 실행되지 않습니다. @TestPropertySource를 보았지만 통합 테스트에서 실행중인 일부 SQL 스크립트와 응용 프로그램 시작에서 다른 SQL 스크립트를 가지고있는 것만으로 많은 것 같습니다. –