이전 노션 블로그의 DataJpaTest 오류: `Property 'spring.profiles.include' imported from location 'class path resource [application-test.properties]'... (2023.09.12)로부터 마이그레이션된 글입니다.
schema.sql
, data.sql
을 @Sql(location = {})
으로 연결해서 스키마 생성하고 데이터 넣는 방법 절대 추천하지 않음. 로컬에서 Github actions 인스턴스까지 계속 문제 발생함.
무조건 프로젝트/src/test/resources/
안에 테스트용 application-test.yml
생성하고, h2 설정하는 것을 추천
@ActiveProfiles("test")
@DataJpaTest
@TestPropertySource(locations = {"classpath:application-test.yml"})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class CustomerRepositoryTest {
// ~~
}
Property 'spring.profiles.include' imported from location 'class path resource [application-test.properties]' is invalid in a profile specific resource [origin: class path resource [application-test.properties] - 1:25]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:98)
~~~~~
at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.include' imported from location 'class path resource [application-test.properties]' is invalid in a profile specific resource [origin: class path resource [application-test.properties] - 1:25]
at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:125)
~~~~
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:90)
... 87 more
Property 'spring.profiles.include' imported from location 'class path resource [application-test.properties]' is invalid in a profile specific resource [origin: class path resource [application-test.properties] - 1:25]
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.include' imported from location 'class path resource [application-test.properties]' is invalid in a profile specific resource [origin: class path resource [application-test.properties] - 1:25]
at app//org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:125)
at java.base@17.0.8/java.lang.Iterable.forEach(Iterable.java:75)
~~~~
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
yml이 아니라 properties 확장자 사용하면 발생하는 오류
application-test.properties
가 아니라, applicaiton-test.yml
을 설정해야 한다.