啟動 TestContext Framework
Spring TestContext Framework 內部的預設組態足以應付所有常見的使用案例。然而,有時開發團隊或第三方框架可能想要變更預設的 ContextLoader
、實作自訂的 TestContext
或 ContextCache
、擴充 ContextCustomizerFactory
和 TestExecutionListener
實作的預設集合等等。為了對 TestContext Framework 的運作方式進行此類低階控制,Spring 提供了啟動策略。
TestContextBootstrapper
定義了啟動 TestContext Framework 的 SPI。TestContextBootstrapper
由 TestContextManager
用於載入目前測試的 TestExecutionListener
實作,並建構其管理的 TestContext
。您可以使用 @BootstrapWith
直接或作為 meta-annotation,為測試類別(或測試類別階層)組態自訂啟動策略。如果未使用 @BootstrapWith
明確組態啟動器,則會根據 @WebAppConfiguration
的存在與否,使用 DefaultTestContextBootstrapper
或 WebTestContextBootstrapper
。
由於 TestContextBootstrapper
SPI 未來可能會變更(以適應新的需求),我們強烈建議實作者不要直接實作此介面,而是擴充 AbstractTestContextBootstrapper
或其具體子類別之一。