문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
springframework:springboot:test [2020/07/08 14:49] kwon37xi [Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test] |
springframework:springboot:test [2022/08/31 16:02] kwon37xi [SpringBoot Test] |
||
---|---|---|---|
줄 2: | 줄 2: | ||
* [[springframework: | * [[springframework: | ||
* [[java: | * [[java: | ||
- | * [[https:// | + | |
+ | * [[springframework: | ||
+ | | ||
===== @SpringBootTest ===== | ===== @SpringBootTest ===== | ||
* 기본적인 SpringBoot 통합 테스트 어노테이션. | * 기본적인 SpringBoot 통합 테스트 어노테이션. | ||
* 이 안에 들어가면 '' | * 이 안에 들어가면 '' | ||
+ | * | ||
+ | '' | ||
+ | |||
+ | ==== @SpringBootApplication 클래스 탐지 ==== | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
==== 테스트용 프라퍼티 지정 ==== | ==== 테스트용 프라퍼티 지정 ==== | ||
<code java> | <code java> | ||
@SpringBootTest(properties = {" | @SpringBootTest(properties = {" | ||
webEnvironment = SpringBootTest.WebEnvironment.NONE) | webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
+ | </ | ||
+ | |||
+ | ==== Context Cache ==== | ||
+ | * 기본적으로 Application Context 를 Cache 한다. | ||
+ | * 하지만 일부 테스트의 설정에서 [[https:// | ||
+ | * 이로인해 성능저하가 심해질 수 있으므로 되도록 컨텍스트를 하나 혹은 최소한의 공통으로 유지하는 것이 중요하다. | ||
+ | * 캐시를 한다는 뜻은 새로운 컨텍스트를 생성해야 하는 상황에서 기존 컨텍스트를 그대로 유지하는 것이다. | ||
+ | * 즉, DB 접속등이 이뤄지는 컨텍스트의 경우 connection pool 로 인해서 DB 서버의 커넥션 수가 꽉차는 상황이 발생할 수 있다. | ||
+ | * **Test 용 설정에서 Connection Pool의 min 사이즈는 작게 잡는게 좋다** | ||
+ | * [[https:// | ||
+ | <code properties> | ||
+ | # 32mb 기본값 | ||
+ | spring.test.context.cache.maxSize=32 | ||
+ | </ | ||
+ | ==== @TestConfiguration ==== | ||
+ | * [[https:// | ||
+ | * Test 용 '' | ||
+ | * [[https:// | ||
+ | * 기존 Bean 설정을 override 하거나 더 추가한다. | ||
+ | * '' | ||
+ | * 혹은 '' | ||
+ | * Test 시에는 기존 bean 을 override 해야 할 수 있기 때문에 관련 프라퍼티를 지정한다. 가급적 production 코드에서는 '' | ||
+ | |||
+ | <code properties> | ||
+ | spring.main.allow-bean-definition-overriding=true | ||
</ | </ | ||
줄 34: | 줄 68: | ||
* 패키지 구조가 다르면 '' | * 패키지 구조가 다르면 '' | ||
* 테스트 '' | * 테스트 '' | ||
- | * '' | ||
- | |||
<code java> | <code java> | ||
@SpringBootTest(classes = SpringBootTestApplication.class, | @SpringBootTest(classes = SpringBootTestApplication.class, | ||
줄 81: | 줄 113: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// |