@TargetSE(valueSE=TYPESE) @RetentionSE(valueSE=RUNTIMESE) @DocumentedSE @InheritedSE @BootstrapWith(value=org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper.class) @ExtendWith(value=org.springframework.test.context.junit.jupiter.SpringExtension.class) @OverrideAutoConfiguration(enabled=false) @TypeExcludeFilters(value=WebMvcTypeExcludeFilter.class) @AutoConfigureCache @AutoConfigureWebMvc @AutoConfigureMockMvc @ImportAutoConfiguration public @interface WebMvcTest
このアノテーションを使用すると、完全な自動構成が無効になり、代わりに MVC テストに関連する構成のみが適用されます(つまり、@Controller
、@ControllerAdvice
、@JsonComponent
、Converter
/GenericConverter
、Filter
、WebMvcConfigurer
、HandlerMethodArgumentResolver
Bean であり、@Component
、@Service
、@Repository
Bean は適用されません)。
デフォルトでは、@WebMvcTest
アノテーションが付けられたテストは、Spring Security および MockMvc
を自動構成します(HtmlUnit WebClient および Selenium WebDriver のサポートを含む)。MockMVC をより細かく制御するには、@AutoConfigureMockMvc
アノテーションを使用できます。
通常、@WebMvcTest
は @MockBean
または @Import
と組み合わせて使用され、@Controller
Bean に必要なコラボレーターを作成します。
完全なアプリケーション構成をロードして MockMVC を使用する場合は、このアノテーションではなく @SpringBootTest
と @AutoConfigureMockMvc
の組み合わせを検討する必要があります。
JUnit 4 を使用する場合、このアノテーションは @RunWith(SpringRunner.class)
と組み合わせて使用する必要があります。
AutoConfigureWebMvc
, AutoConfigureMockMvc
, AutoConfigureCache
修飾子と型 | オプションの要素と説明 |
---|---|
ClassSE<?>[] | controllers テストするコントローラーを指定します。 |
ClassSE<?>[] | excludeAutoConfiguration このテストに適用する必要がある自動構成の除外。 |
ComponentScan.Filter[] | excludeFilters それ以外の場合はアプリケーションコンテキストに追加される Bean のフィルタリングに使用できる除外フィルターのセット。 |
ComponentScan.Filter[] | includeFilters 他の方法でフィルタリングされた Bean をアプリケーションコンテキストに追加するために使用できる一連の組み込みフィルター。 |
StringSE[] | properties テストの実行前に Spring Environment に追加する必要がある key = value 形式のプロパティ。 |
boolean | useDefaultFilters @SpringBootApplication でデフォルトのフィルタリングを使用するかどうかを決定します。 |
ClassSE<?>[] | value テストするコントローラーを指定します。 |
public abstract StringSE[] properties
Environment
に追加する必要がある key = value 形式のプロパティ。@AliasFor(value="controllers") public abstract ClassSE<?>[] value
controllers()
のエイリアスです。詳細については、controllers()
を参照してください。controllers()
public abstract boolean useDefaultFilters
@SpringBootApplication
でデフォルトのフィルタリングを使用するかどうかを決定します。デフォルトでは、@Controller
(明示的な controllers
が定義されていない場合)、@ControllerAdvice
および WebMvcConfigurer
Bean のみが含まれます。includeFilters()
, excludeFilters()
public abstract ComponentScan.Filter[] includeFilters
public abstract ComponentScan.Filter[] excludeFilters
@AliasFor(annotation=ImportAutoConfiguration.class, attribute="exclude") public abstract ClassSE<?>[] excludeAutoConfiguration