사용자 도구

사이트 도구


springframework:springboot:test

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
springframework:springboot:test [2022/03/25 14:17]
kwon37xi [테스트용 프라퍼티 지정]
springframework:springboot:test [2022/08/31 16:02] (현재)
kwon37xi [SpringBoot Test]
줄 3: 줄 3:
   * [[java:junit:5|JUnit 5]]   * [[java:junit:5|JUnit 5]]
   * [[springframework:springboot:mvc|SpringBoot and Spring MVC]]   * [[springframework:springboot:mvc|SpringBoot and Spring MVC]]
-  * [[https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure|Spring Boot Test Autoconfigure]] 여기에서 각종 test 자동화 Annotation을 확인할 수 있다.+  * [[springframework:springboot:webmvctest|SpringBoot WebMvcTest]] 
 +  [[https://docs.spring.io/spring-boot/docs/current/reference/html/test-auto-configuration.html|Test Auto-configuration Annotations]] / [[https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure|Spring Boot Test Autoconfigure]] 여기에서 각종 test 자동화 Annotation을 확인할 수 있다.
  
 ===== @SpringBootTest ===== ===== @SpringBootTest =====
   * 기본적인 SpringBoot 통합 테스트 어노테이션.   * 기본적인 SpringBoot 통합 테스트 어노테이션.
   * 이 안에 들어가면 ''@ExtendWith(SpringExtension.class)''가 함께 지정되어 있어서 JUnit 5에서 자동 수행된다.   * 이 안에 들어가면 ''@ExtendWith(SpringExtension.class)''가 함께 지정되어 있어서 JUnit 5에서 자동 수행된다.
 +  * 
 +''@ExtendWith(SpringExtension.class)'' 는 SpringBoot 2.1 부터 ''@SpringBootTest'' 와 그 하위 애노테이션(''@DataJpaTest'' 등)에 기본 내장돼 있으므로 테스트 클래스에 지정할 필요가 없다.
  
-==== ''@SpringBootApplication'' 클래스 탐지 ====+==== @SpringBootApplication 클래스 탐지 ====
   * ''@SpringBootTest'' 는 이 애노테이션이 지정된 클래스보다 아래에 있거나 동일 패키지 경로상의 상위 패키지에 존재하는 ''@SpringBootApplication'' 클래스도 자동 탐지한다.   * ''@SpringBootTest'' 는 이 애노테이션이 지정된 클래스보다 아래에 있거나 동일 패키지 경로상의 상위 패키지에 존재하는 ''@SpringBootApplication'' 클래스도 자동 탐지한다.
   * ''classes={}'' 로 명시할 수도 있다.   * ''classes={}'' 로 명시할 수도 있다.
줄 26: 줄 29:
   * 즉, DB 접속등이 이뤄지는 컨텍스트의 경우 connection pool 로 인해서 DB 서버의 커넥션 수가 꽉차는 상황이 발생할 수 있다.   * 즉, DB 접속등이 이뤄지는 컨텍스트의 경우 connection pool 로 인해서 DB 서버의 커넥션 수가 꽉차는 상황이 발생할 수 있다.
   * **Test 용 설정에서 Connection Pool의 min 사이즈는 작게 잡는게 좋다**   * **Test 용 설정에서 Connection Pool의 min 사이즈는 작게 잡는게 좋다**
- +  * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/cache/DefaultContextCache.html|DefaultContextCache]] : 기본 컨텍스트 캐시 구현체 ''spring.test.context.cache.maxSize'' 프라퍼티에 **''mb''** 단위로 지정. 
-==== '@TestConfiguration'' ====+<code properties> 
 +# 32mb 기본값 
 +spring.test.context.cache.maxSize=32 
 +</code> 
 +==== @TestConfiguration ====
   * [[https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/TestConfiguration.html|@TestConfiguration]]   * [[https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/TestConfiguration.html|@TestConfiguration]]
   * Test 용 ''@Configuration''   * Test 용 ''@Configuration''
줄 34: 줄 41:
   * ''@Configuration'' 은 component scan 으로 자동으로 탐지되지만 ''@TestConfiguration'' 은 자동탐지를 하지 않고 ''import'' 명시할 때만 작동한다. 테스트시 오작동을 줄일 수 있다.   * ''@Configuration'' 은 component scan 으로 자동으로 탐지되지만 ''@TestConfiguration'' 은 자동탐지를 하지 않고 ''import'' 명시할 때만 작동한다. 테스트시 오작동을 줄일 수 있다.
   * 혹은 ''@SpringBootTest'' 가 지정된 클래스의 ''static'' inner class 로 만들어 지정하면 자동 탐지한다.   * 혹은 ''@SpringBootTest'' 가 지정된 클래스의 ''static'' inner class 로 만들어 지정하면 자동 탐지한다.
-  * Test 시에는 기존 bean 을 override 해야 할 수 있기 때문에 ''spring.main.allow-bean-definition-overriding=true'' 프라퍼티를 지정한다. 가급적 production 코드에서는 ''false''로 둬야한다.+  * Test 시에는 기존 bean 을 override 해야 할 수 있기 때문에 관련 프라퍼티를 지정한다. 가급적 production 코드에서는 ''false''로 둬야한다. 
 + 
 +<code properties> 
 +spring.main.allow-bean-definition-overriding=true 
 +</code>
  
 ==== Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test ==== ==== Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test ====
줄 103: 줄 114:
   * [[https://goddaehee.tistory.com/212?category=367461|갓대희의 작은공간 :: [스프링부트 (10)] SpringBoot Test(3) - 단위 테스트(@WebMvcTest, @DataJpaTest, @RestClientTest 등)]]   * [[https://goddaehee.tistory.com/212?category=367461|갓대희의 작은공간 :: [스프링부트 (10)] SpringBoot Test(3) - 단위 테스트(@WebMvcTest, @DataJpaTest, @RestClientTest 등)]]
   * [[http://wonwoo.ml/index.php/post/1926|Spring Boot test annotation - 머루의개발블로그]]   * [[http://wonwoo.ml/index.php/post/1926|Spring Boot test annotation - 머루의개발블로그]]
 +  * [[https://huisam.tistory.com/entry/springBootTest|Spring Boot Context Test - 스프링 컨텍스트 테스트 (aka. IntegrationTest) — 천천히 올바르게]]
 +  * [[https://reflectoring.io/spring-boot-test/|Testing with Spring Boot and @SpringBootTest]]
springframework/springboot/test.1648185424.txt.gz · 마지막으로 수정됨: 2022/03/25 14:17 저자 kwon37xi