扩展类 SpringExtension
1. beforeAll() 方法
1. 创建了 TestContextManager 对象
createBootstrapContext 创建了applicationContext
DefaultCacheAwareContextLoaderDelegate#loadContextInternal
<font color="#ff00ff">SpringBootContextLoader#loadContext (重要)</font>
2. 加载 TestExecutionListeners (两种策略)
1. 从测试类上加载注解 @TestExecutionListeners
2. 加载默认的 spring.factories
3. 执行 TestExecutionListener#beforeTestClass 回调方法
2. postProcessTestInstance() 方法
1. 执行 TestExecutionListener#prepareTestInstance回调方法
3. beforeEach() 方法
1. 执行 TestExecutionListener#beforeTestMethod 回调方法
4. beforeTestExecution() 方法
1. 执行 TestExecutionListener#beforeTestMethod 回调方法
5. afterTestExecution() 方法
1. 执行 TestExecutionListener#afterTestExecution 回调方法
6. afterEach() 方法
1. 执行 TestExecutionListener#afterTestMethod 回调方法
7. afterAll() 方法
1. 执行 TestExecutionListener#afterTestClass 回调方法
重要的 TestExecutionListener 类
1. DependencyInjectionTestExecutionListener
2. MockitoTestExecutionListener
prepareTestInstance 初始化注入bean
<font color="#ff00ff">beforeTestMethod 重新注入bean 非常重要</font>
3. EventPublishingTestExecutionListener
重要的 ContextCustomizerFactory 类
MockitoContextCustomizerFactory
DefinitionsParser parser = new DefinitionsParser()
parseDefinitions(testClass, parse) 解析testClass中的mockBean
<font color="#00ff00">MockitoContextCustomizer</font>
注册 MockitoPostProcessor