引導 TestContext 框架

對於所有常見用例,Spring TestContext 框架內部結構的預設配置已經足夠。但是,有時開發團隊或第三方框架可能希望更改預設的 ContextLoader、實現自定義的 TestContextContextCache、增強預設的 ContextCustomizerFactoryTestExecutionListener 實現集合等。為了對 TestContext 框架的操作方式進行這種低階控制,Spring 提供了引導策略。

TestContextBootstrapper 定義了引導 TestContext 框架的 SPI。TestContextManager 使用 TestContextBootstrapper 來載入當前測試的 TestExecutionListener 實現,並構建它管理的 TestContext。您可以透過直接或作為元註解使用 @BootstrapWith 為測試類(或測試類層次結構)配置自定義引導策略。如果未使用 @BootstrapWith 明確配置載入程式,則將使用 DefaultTestContextBootstrapperWebTestContextBootstrapper,具體取決於是否存在 @WebAppConfiguration

由於 TestContextBootstrapper SPI 未來可能會更改(以適應新的需求),我們強烈建議實現者不要直接實現此介面,而是擴充套件 AbstractTestContextBootstrapper 或其具體子類之一。