@WebMvcTest와 @SpringBootTest annotation이 있는데 이들의 차이가 뭔지 궁금해 알아보기로 했다.@ContextConfiguration을 대체함.@SpringBootTest는 서버를 실행시키지 않는다.webEnvironment 속성을 사용해서 여러 설정이 가능함.MOCK(Default) : Web ApplicationContext를 로드하고 가짜 web 환경을 제공. 이 annotation을 사용하면 임베디드 서버가 시작하지 않는다.RANDOM_PORT, DEFINED_PORT, NONE이 있다.RANDOM_PORT와 DEFINED_PORT의 경우 실제 웹 환경을 제공함. -> 다만 포트 번호가 랜덤이냐 아니냐의 차이.@RunWith(SpringRunner.class)가 필요했지만 현재는 그렇지 않음.@RunWith가 아닌 Extension이라는 방법을 통해 테스트를 실행하는 방법을 커스터마이징함.@ExtendWith(SpringExtension.class)을 사용하면 되지만, 이미 스프링 부트에서 제공하는 모든 테스트용 annotation에 meta annotation으로 적용되어 생략이 가능하다.If you are using JUnit 4, do not forget to also add @RunWith(SpringRunner.class) to your test, otherwise the annotations will be ignored. If you are using JUnit 5, there is no need to add the equivalent @ExtendWith(SpringExtension.class) as @SpringBootTest and the other @…Test annotations are already annotated with it. - 공식문서
@MockBean이나 @Import와 함께 사용된다고 한다.Typically @WebMvcTest is used in combination with @MockBean or @Import to create any collaborators required by your @Controller beans. - 공식문서
SpringBootTest 공식문서
WebMvcTest 공식문서
meetup toast
SpringBoot공식문서
백기선님 글