JDBC 기반 컴포넌트만 테스트하는 JDBC 테스트를 위한 어노테이션이다.
https://velog.io/@hooni_/%EC%8A%A4%ED%94%84%EB%A7%81-JdbcTest
테이블에 대한 롤백은 시켜주나, auto-Increment에 대한 롤백은 되지 않는다.
https://unluckyjung.github.io/testcode/2021/05/08/Independent-Test-Mehod/
Using this annotation will
disable full auto-configuration
and insteadapply only configuration relevant to MVC tests
(i.e. @Controller, @ControllerAdvice, @JsonComponent, Converter/GenericConverter, Filter, WebMvcConfigurer and HandlerMethodArgumentResolver beans but not @Component, @Service or @Repository beans).
@WebMvcTest 어노테이션을 사용시 다음 내용만 스캔하도록 제한한다
@Controller,
@ControllerAdvice,
@JsonComponent,
Converter,
GenericConverter,
Filter,
WebSecurityConfigurerAdapter,
WebMvcConfigurer,
HandlerMethodArgumentResolver
@Component
, @Service
, @Repository
Bean들은 스캔에서 제외된다.
2) 장점
3) 단점
WebMvcConfigurer
에서 의존성 주입을 하지않아서 에러가 발생했었다.
@WebMvcTest(value = ViewController.class,
excludeFilters = {@ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
classes = WebMvcConfigurer.class
)}
)
https://hyeon9mak.github.io/component-and-component-scan/
실제 객체를 만들어 사용하기에 시간, 비용 등의 Cost가 높거나 혹은 객체 서로간의 의존성이 강해 구현하기 힘들 경우 가짜 객체를 만들어 사용하는 방법이다
mock 객체를 생성한다.
@InjectMocks라는 어노테이션이 존재하는데, @Mock이 붙은 목객체를 @InjectMocks이 붙은 객체에 주입시킬 수 있다.
Mock 객체들을 Spring의 ApplicationContext에 넣어준다. 그리고 동일한 타입의 Bean이 존재할 경우 MockBean으로 교체해준다.
https://blusky10.tistory.com/330
https://azderica.github.io/00-test-mock-and-stub/
테스트를 실행하기 전 원하는 sql문을 실행시켜주는 어노테이션입니다. 단위 테스트를 위해 값이 미리