引導 TestContext 框架

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

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

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

© . This site is unofficial and not affiliated with VMware.