Spring-boot 만을 이용해 코드를 작성하고, 후에 Spring-security를 적용해서 코드를 작성 후, Gradle의 전체 테스트를 진행했을 때, lombok을 사용한 테스트 외에 스프링을 이용한 테스트는 모두 실패한다. 이것은 src/main 과 src/test의 환경의 차이로 인해 발생한다.
src/main(이하 메인) 과, src/test(이하 테스트)는 본인만의 환경 구성을 갖는다. 다만, application.properties가 테스트 코드를 수행할 때도 적용되는 이유는 테스트에 application.properties가 없으면 메인의 설정을 그대로 가져오기 때문이다. 다만, 자동으로 가져오는 옵션의 범위는 application.properties 파일 까지다.
따라서 application-oauth.properties는 test에 파일이 없다고 가져오는 파일은 아니라는점이다.
이 문제를 해결하기 위해 테스트 환경을 위한 application.properties를 새로 생성해야 한다.
spring.jpa.show_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.h2.console.enabled=true
spring.profiles.include=oauth
spring.session.store-type=jdbc
# Test OAuth
spring.security.oauth2.client.registration.google.client-id=test
spring.security.oauth2.client.registration.google.client-secret=test
spring.security.oauth2.client.registration.google.scope=profile,email
@WebMvcTest에서 CustomOAuth2UserService을 찾을 수 없음 (0) | 2020.06.29 |
---|---|
Spring-security 모듈 추가 후 테스트 에러 해결 (0) | 2020.06.29 |
Spring_boot를 테스트하기 위한 어노테이션 및 메소드 (0) | 2020.06.29 |
Spring-boot HTML Test (0) | 2020.06.24 |
단위 테스트 소개 (0) | 2020.06.18 |