인프런 커뮤니티 질문&답변

뽀랜돈님의 프로필 이미지
뽀랜돈

작성한 질문수

스프링 DB 2편 - 데이터 접근 활용 기술

테스트 - 데이터베이스 연동

spring.profile.active=test 에러

작성

·

863

1

안녕하세요. 강의에서 말씀해주신 /src/test/resources/application.properties 파일에서 테스트 profile설정을 완료 했는데요. 

ItemRepositoryTest 실행 시 테스트 profile 설정을 읽어오지 못하는 것 같아서 질문 드려요. 실행해보면 아래 메세지가 뜨고, 스프링이 띄워지는데 profile 정보가 "local"로 잡히네요. 원인을 검색해봤는데 해결 가능한 답변을 찾지 못해서 질문드립니다. ㅠ

 

18:03:27.880 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]

18:03:27.918 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]

18:03:28.051 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [hello.itemservice.domain.ItemRepositoryTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]

18:03:28.088 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [hello.itemservice.domain.ItemRepositoryTest], using SpringBootContextLoader

18:03:28.103 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [hello.itemservice.domain.ItemRepositoryTest]: class path resource [hello/itemservice/domain/ItemRepositoryTest-context.xml] does not exist

18:03:28.105 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [hello.itemservice.domain.ItemRepositoryTest]: class path resource [hello/itemservice/domain/ItemRepositoryTestContext.groovy] does not exist

18:03:28.105 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [hello.itemservice.domain.ItemRepositoryTest]: no resource found for suffixes {-context.xml, Context.groovy}.

18:03:28.107 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [hello.itemservice.domain.ItemRepositoryTest]: ItemRepositoryTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.

18:03:28.176 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [hello.itemservice.domain.ItemRepositoryTest]

18:03:28.261 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [C:\workspaces\spring-db-2\itemservice-db\bin\main\hello\itemservice\ItemServiceApplication.class]

18:03:28.264 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration hello.itemservice.ItemServiceApplication for test class hello.itemservice.domain.ItemRepositoryTest

18:03:28.407 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [hello.itemservice.domain.ItemRepositoryTest]: using defaults.

18:03:28.408 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]

18:03:28.432 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@1f6c9cd8, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@5b619d14, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@66746f57, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@447a020, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@7f36662c, org.springframework.test.context.support.DirtiesContextTestExecutionListener@28e8dde3, org.springframework.test.context.transaction.TransactionalTestExecutionListener@6d23017e, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@54dcfa5a, org.springframework.test.context.event.EventPublishingTestExecutionListener@1817f1eb, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@767e20cf, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@3a3e78f, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@301ec38b, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@17a1e4ca, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@10ded6a9, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@c5dc4a2]

18:03:28.437 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@35d08e6c testClass = ItemRepositoryTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@53d102a2 testClass = ItemRepositoryTest, locations = '{}', classes = '{class hello.itemservice.ItemServiceApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@4b8d604b, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@3932c79a, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@821330f, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@210ab13f, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@6a4f1a55, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@4c40b76e], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].

 

INFO 15312 --- [           main] h.itemservice.domain.ItemRepositoryTest  : The following 1 profile is active: "local"

답변 2

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. 뽀랜돈님

이클립스의 경우 약간 다른 방법이 필요한데요.

이클립스 application.properties로 검색해보시면 방법을 찾을 수 있을거에요.

감사합니다.

0

뽀랜돈님의 프로필 이미지
뽀랜돈
질문자

이것저것 찾아보며 확인해봤는데 IDE에서 테스트 케이스(ItemRepositoryTest) 실행 시, 프로파일이 계속 "local"로 떠서 해결이 안되었습니다. 혹시나 해서 CLI환경에서 gradle로 테스트를 돌려보니 정상적으로 /src/test/resources/application.properties 프로파일을 읽어오면서 테스트를 성공했습니다. 저는 실습을 STS환경에서 하고 있는데 IDE에서 뭔가 설정이 더 필요한 건지 모르겠네요... ㅠㅠ 강의 로드맵 첫 강의부터 IntelliJ사용을 추천해주셨는데 제가 아직 써보지 않은 툴이고 사용법 익히는데 시간이 또 들거 같아서 그냥 STS를 사용했는데 ㅠㅠ

아무튼 공부진행을 위해 프로파일 관련 문제는 북마크 해놓고 차후에 다시 봐야될 것 같아요.

감사합니다.

뽀랜돈님의 프로필 이미지
뽀랜돈

작성한 질문수

질문하기