본문 바로가기
CS study

Answer the Question (5)

by DaSsom 2023. 7. 25.

1. Spring 에서 사용하는 Rest Client에 대해서 설명해 주세요.

더보기

2. @SpringBootTest와 @WebMvcTest의 차이점을 설명해 주세요.

더보기

@SpringBootTest는 프로젝트의 전체 컨텍스트를 로드하여 빈을 주입하기 때문에 속도가 느리고, 통합 테스트를 할 때 많이 사용한다. 많은 스프링 빈을 등록하여 테스트에 필요한 의존성을 추가하기 때문에, 필요한 빈만을 등록하여 테스트를 진행하고자 한다면 슬라이스 테스트 어노테이션인 @WebMvcTest를 사용하는 것이 더 효율적이다.

@WebMvcTest는 MVC 부분 슬라이스 테스트로, 보통 컨트롤러 하나만 테스트하고 싶을 때 사용한다. @WebMvcTest()의 프로퍼티로 테스트를 원하는 컨트롤러 클래스를 넣어준다. @WebMvcTest는 @Controller같은 웹과 관련된 빈만 주입되며 @Service와 같은 일반적인 @Component는 생성되지 않는 특성 때문에 해당 컨트롤러를 생성하는 데 필요한 다른 빈을 정의하지 못해 발생한다. 따라서 이런 경우에는 @MockBean을 사용해서 필요한 의존성을 채워주어야 한다.

 

 

 

 

https://docs.spring.io/spring-framework/reference/integration/rest-clients.html

 

REST Clients :: Spring Framework

WebClient is a non-blocking, reactive client to perform HTTP requests. It was introduced in 5.0 and offers an alternative to the RestTemplate, with support for synchronous, asynchronous, and streaming scenarios. WebClient supports the following: Non-blocki

docs.spring.io

 

'CS study' 카테고리의 다른 글

Answer the Question (7)  (0) 2023.07.27
Answer the Question (6)  (0) 2023.07.26
Answer the Question (4)  (0) 2023.07.24
Answer the Question (3)  (0) 2023.07.21
Answer the Question (2)  (0) 2023.07.20