接口的使用
cn.taketoday.test.context.TestContext
使用TestContext的程序包
程序包
说明
Classes and annotations related to configuring Infra
ApplicationContext for
tests.Mockito integration for tests.
This package contains the TestContext Framework which
provides annotation-driven unit and integration testing support that is
agnostic of the actual testing framework in use.
Test event support classes for the TestContext Framework.
JDBC support classes for the TestContext Framework,
including support for declarative SQL script execution via
@Sql.Support classes for the TestContext Framework.
Transactional support classes for the TestContext Framework.
Web support classes for the TestContext Framework.
-
cn.taketoday.framework.test.context中TestContext的使用
-
cn.taketoday.framework.test.mock.mockito中TestContext的使用
修饰符和类型方法说明voidMockitoTestExecutionListener.afterTestMethod(TestContext testContext) voidResetMocksTestExecutionListener.afterTestMethod(TestContext testContext) voidMockitoTestExecutionListener.beforeTestMethod(TestContext testContext) voidResetMocksTestExecutionListener.beforeTestMethod(TestContext testContext) private booleanMockitoTestExecutionListener.hasMockitoAnnotations(TestContext testContext) private voidMockitoTestExecutionListener.initMocks(TestContext testContext) private voidMockitoTestExecutionListener.injectFields(TestContext testContext) private voidMockitoTestExecutionListener.postProcessFields(TestContext testContext, BiConsumer<MockitoTestExecutionListener.MockitoField, MockitoPostProcessor> consumer) voidMockitoTestExecutionListener.prepareTestInstance(TestContext testContext) private voidMockitoTestExecutionListener.reinjectFields(TestContext testContext) -
cn.taketoday.test.context中TestContext的使用
类型参数类型为TestContext的cn.taketoday.test.context中的字段修饰符和类型方法说明TestContextBootstrapper.buildTestContext()Build theTestContextfor theBootstrapContextassociated with this bootstrapper.private static TestContextTestContextManager.copyTestContext(TestContext testContext) Attempt to create a copy of the suppliedTestContextusing its copy constructor.final TestContextTestContextManager.getTestContext()Get theTestContextmanaged by thisTestContextManager.参数类型为TestContext的cn.taketoday.test.context中的方法修饰符和类型方法说明default voidTestExecutionListener.afterTestClass(TestContext testContext) Post-processes a test class after execution of all tests within the class.default voidTestExecutionListener.afterTestExecution(TestContext testContext) Post-processes a test immediately after execution of the test method in the supplied test context — for example, for timing or logging purposes.default voidTestExecutionListener.afterTestMethod(TestContext testContext) Post-processes a test after execution of after lifecycle callbacks of the underlying test framework — for example, by tearing down test fixtures.default voidTestExecutionListener.beforeTestClass(TestContext testContext) Pre-processes a test class before execution of all tests within the class.default voidTestExecutionListener.beforeTestExecution(TestContext testContext) Pre-processes a test immediately before execution of the test method in the supplied test context — for example, for timing or logging purposes.default voidTestExecutionListener.beforeTestMethod(TestContext testContext) Pre-processes a test before execution of before lifecycle callbacks of the underlying test framework — for example, by setting up test fixtures.private static TestContextTestContextManager.copyTestContext(TestContext testContext) Attempt to create a copy of the suppliedTestContextusing its copy constructor.default voidTestExecutionListener.prepareTestInstance(TestContext testContext) Prepares the test instance of the supplied test context — for example, to inject dependencies.类型变量类型为TestContext的cn.taketoday.test.context中的方法参数修饰符和类型方法说明default voidTestContext.publishEvent(Function<TestContext, ? extends cn.taketoday.context.ApplicationEvent> eventFactory) Publish theApplicationEventcreated by the giveneventFactoryto the application context for this test context. -
cn.taketoday.test.context.event中TestContext的使用
修饰符和类型方法说明final TestContextTestContextEvent.getSource()Get theTestContextassociated with this event.final TestContextTestContextEvent.getTestContext()Alias forTestContextEvent.getSource().修饰符和类型方法说明voidEventPublishingTestExecutionListener.afterTestClass(TestContext testContext) voidEventPublishingTestExecutionListener.afterTestExecution(TestContext testContext) voidApplicationEventsTestExecutionListener.afterTestMethod(TestContext testContext) voidEventPublishingTestExecutionListener.afterTestMethod(TestContext testContext) voidEventPublishingTestExecutionListener.beforeTestClass(TestContext testContext) voidEventPublishingTestExecutionListener.beforeTestExecution(TestContext testContext) voidApplicationEventsTestExecutionListener.beforeTestMethod(TestContext testContext) voidEventPublishingTestExecutionListener.beforeTestMethod(TestContext testContext) voidApplicationEventsTestExecutionListener.prepareTestInstance(TestContext testContext) voidEventPublishingTestExecutionListener.prepareTestInstance(TestContext testContext) private booleanApplicationEventsTestExecutionListener.recordApplicationEvents(TestContext testContext) 参数类型为TestContext的cn.taketoday.test.context.event中的构造器限定符构造器说明AfterTestClassEvent(TestContext source) AfterTestExecutionEvent(TestContext source) AfterTestMethodEvent(TestContext source) BeforeTestClassEvent(TestContext source) BeforeTestExecutionEvent(TestContext source) BeforeTestMethodEvent(TestContext source) PrepareTestInstanceEvent(TestContext source) TestContextEvent(TestContext source) Create a newTestContextEvent. -
cn.taketoday.test.context.jdbc中TestContext的使用
修饰符和类型方法说明voidSqlScriptsTestExecutionListener.afterTestClass(TestContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedTestContextonce per test class after all test methods have been run.voidSqlScriptsTestExecutionListener.afterTestMethod(TestContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedTestContextafter the current test method.voidSqlScriptsTestExecutionListener.beforeTestClass(TestContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedTestContextonce per test class before any test method is run.voidSqlScriptsTestExecutionListener.beforeTestMethod(TestContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedTestContextbefore the current test method.private voidSqlScriptsTestExecutionListener.executeClassLevelSqlScripts(TestContext testContext, Sql.ExecutionPhase executionPhase) Execute class-level SQL scripts configured via@Sqlfor the suppliedTestContextand the suppliedBEFORE_TEST_CLASSorAFTER_TEST_CLASSexecution phase.private voidSqlScriptsTestExecutionListener.executeSqlScripts(Sql sql, Sql.ExecutionPhase executionPhase, TestContext testContext, boolean classLevel) Execute the SQL scripts configured via the supplied@Sqlannotation for the givenSql.ExecutionPhaseandTestContext.private voidSqlScriptsTestExecutionListener.executeSqlScripts(TestContext testContext, Sql.ExecutionPhase executionPhase) private voidSqlScriptsTestExecutionListener.executeSqlScripts(Set<Sql> sqlAnnotations, TestContext testContext, Sql.ExecutionPhase executionPhase, boolean classLevel) Execute SQL scripts for the supplied@Sqlannotations.private booleanSqlScriptsTestExecutionListener.mergeSqlAnnotations(TestContext testContext) Determine if method-level@Sqlannotations should be merged with class-level@Sqlannotations. -
cn.taketoday.test.context.support中TestContext的使用
修饰符和类型方法说明AbstractTestContextBootstrapper.buildTestContext()Build a newDefaultTestContextusing the test class in theBootstrapContextassociated with this bootstrapper and by delegating toAbstractTestContextBootstrapper.buildMergedContextConfiguration()andAbstractTestContextBootstrapper.getCacheAwareContextLoaderDelegate().修饰符和类型方法说明voidAbstractTestExecutionListener.afterTestClass(TestContext testContext) The default implementation is empty.voidDirtiesContextTestExecutionListener.afterTestClass(TestContext testContext) If the test class of the supplied test context is annotated with@DirtiesContextand the class mode is set toAFTER_CLASS, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.voidAbstractTestExecutionListener.afterTestExecution(TestContext testContext) The default implementation is empty.voidAbstractTestExecutionListener.afterTestMethod(TestContext testContext) The default implementation is empty.voidDirtiesContextTestExecutionListener.afterTestMethod(TestContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContextand the method mode is set toAFTER_METHOD, or if the test class is annotated with@DirtiesContextand the class mode is set toAFTER_EACH_TEST_METHOD, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.protected voidAbstractDirtiesContextTestExecutionListener.beforeOrAfterTestClass(TestContext testContext, DirtiesContext.ClassMode requiredClassMode) Perform the actual work forAbstractTestExecutionListener.beforeTestClass(cn.taketoday.test.context.TestContext)andAbstractTestExecutionListener.afterTestClass(cn.taketoday.test.context.TestContext)by dirtying the context if appropriate (i.e., according to the required mode).protected voidAbstractDirtiesContextTestExecutionListener.beforeOrAfterTestMethod(TestContext testContext, DirtiesContext.MethodMode requiredMethodMode, DirtiesContext.ClassMode requiredClassMode) Perform the actual work forAbstractTestExecutionListener.beforeTestMethod(cn.taketoday.test.context.TestContext)andAbstractTestExecutionListener.afterTestMethod(cn.taketoday.test.context.TestContext)by dirtying the context if appropriate (i.e., according to the required modes).voidAbstractTestExecutionListener.beforeTestClass(TestContext testContext) The default implementation is empty.voidDirtiesContextBeforeModesTestExecutionListener.beforeTestClass(TestContext testContext) If the test class of the supplied test context is annotated with@DirtiesContextand the class mode is set toBEFORE_CLASS, the application context of the test context will be marked as dirty, and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.voidAbstractTestExecutionListener.beforeTestExecution(TestContext testContext) The default implementation is empty.voidAbstractTestExecutionListener.beforeTestMethod(TestContext testContext) The default implementation is empty.voidDependencyInjectionTestExecutionListener.beforeTestMethod(TestContext testContext) If theDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTEin the suppliedtest contexthas a value ofBoolean.TRUE, this method will have the same effect asprepareTestInstance(); otherwise, this method will have no effect.voidDirtiesContextBeforeModesTestExecutionListener.beforeTestMethod(TestContext testContext) If the current test method of the supplied test context is annotated with@DirtiesContextand the method mode is set toBEFORE_METHOD, or if the test class is annotated with@DirtiesContextand the class mode is set toBEFORE_EACH_TEST_METHOD, the application context of the test context will be marked as dirty and theREINJECT_DEPENDENCIES_ATTRIBUTEin the test context will be set totrue.protected voidAbstractDirtiesContextTestExecutionListener.dirtyContext(TestContext testContext, DirtiesContext.HierarchyMode hierarchyMode) Mark the application context of the supplied test context as dirty and setREINJECT_DEPENDENCIES_ATTRIBUTEin the test context totrue.protected voidDependencyInjectionTestExecutionListener.injectDependencies(TestContext testContext) Performs dependency injection and bean initialization for the suppliedTestContextas described inprepareTestInstance().private voidDependencyInjectionTestExecutionListener.injectDependenciesInAotMode(TestContext testContext) voidAbstractTestExecutionListener.prepareTestInstance(TestContext testContext) The default implementation is empty.voidDependencyInjectionTestExecutionListener.prepareTestInstance(TestContext testContext) Performs dependency injection on thetest instanceof the suppliedtest contextbyautowiringandinitializingthe test instance via its ownapplication context(without checking dependencies). -
cn.taketoday.test.context.transaction中TestContext的使用
修饰符和类型方法说明voidTransactionalTestExecutionListener.afterTestMethod(TestContext testContext) If a transaction is currently active for the supplied test context, this method will end the transaction and run@AfterTransactionmethods.voidTransactionalTestExecutionListener.beforeTestMethod(TestContext testContext) If the test method of the supplied test context is configured to run within a transaction, this method will run@BeforeTransactionmethods and start a new transaction.static cn.taketoday.transaction.interceptor.TransactionAttributeTestContextTransactionUtils.createDelegatingTransactionAttribute(TestContext testContext, cn.taketoday.transaction.interceptor.TransactionAttribute targetAttribute) Create a delegatingTransactionAttributefor the supplied targetTransactionAttributeandTestContext, using the names of the test class and test method to build the name of the transaction.static cn.taketoday.transaction.interceptor.TransactionAttributeTestContextTransactionUtils.createDelegatingTransactionAttribute(TestContext testContext, cn.taketoday.transaction.interceptor.TransactionAttribute targetAttribute, boolean includeMethodName) Create a delegatingTransactionAttributefor the supplied targetTransactionAttributeandTestContext, using the names of the test class and test method (if requested) to build the name of the transaction.protected cn.taketoday.transaction.PlatformTransactionManagerTransactionalTestExecutionListener.getTransactionManager(TestContext testContext) Get the transaction manager to use for the supplied test context.protected cn.taketoday.transaction.PlatformTransactionManagerTransactionalTestExecutionListener.getTransactionManager(TestContext testContext, String qualifier) Get the transaction manager to use for the supplied test context andqualifier.protected final booleanTransactionalTestExecutionListener.isDefaultRollback(TestContext testContext) Determine whether or not to rollback transactions by default for the supplied test context.protected final booleanTransactionalTestExecutionListener.isRollback(TestContext testContext) Determine whether or not to rollback transactions for the supplied test context by taking into consideration the default rollback flag and a possible method-level override via the@Rollbackannotation.private static voidTestContextTransactionUtils.logBeansException(TestContext testContext, cn.taketoday.beans.BeansException ex, Class<?> beanType) static DataSourceTestContextTransactionUtils.retrieveDataSource(TestContext testContext, String name) Retrieve theDataSourceto use for the supplied test context.static cn.taketoday.transaction.PlatformTransactionManagerTestContextTransactionUtils.retrieveTransactionManager(TestContext testContext, String name) Retrieve the transaction manager to use for the supplied test context.protected voidTransactionalTestExecutionListener.runAfterTransactionMethods(TestContext testContext) Run all@AfterTransactionmethods for the specified test context.protected voidTransactionalTestExecutionListener.runBeforeTransactionMethods(TestContext testContext) Run all@BeforeTransactionmethods for the specified test context.限定符构造器说明TestContextTransactionAttribute(cn.taketoday.transaction.interceptor.TransactionAttribute targetAttribute, TestContext testContext, boolean includeMethodName) (专用程序包)TransactionContext(TestContext testContext, cn.taketoday.transaction.PlatformTransactionManager transactionManager, cn.taketoday.transaction.TransactionDefinition transactionDefinition, boolean defaultRollback) -
cn.taketoday.test.context.web中TestContext的使用
参数类型为TestContext的cn.taketoday.test.context.web中的方法修饰符和类型方法说明voidServletTestExecutionListener.afterTestMethod(TestContext testContext) If theServletTestExecutionListener.RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTEin the suppliedTestContexthas a value ofBoolean.TRUE, this method will (1) clean up thread-local state after each test method by resetting Infra Web'sRequestContextHolderand (2) ensure that new mocks are injected into the test instance for subsequent tests by setting theDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTEin the test context totrue.private booleanServletTestExecutionListener.alreadyPopulatedRequestContextHolder(TestContext testContext) voidServletTestExecutionListener.beforeTestMethod(TestContext testContext) Sets up thread-local state before each test method via Infra Web'sRequestContextHolder, but only if the test class is annotated with@WebAppConfiguration.private booleanServletTestExecutionListener.isActivated(TestContext testContext) voidServletTestExecutionListener.prepareTestInstance(TestContext testContext) Sets up thread-local state during the test instance preparation callback phase via Infra Web'sRequestContextHolder, but only if the test class is annotated with@WebAppConfiguration.private voidServletTestExecutionListener.setUpRequestContextIfNecessary(TestContext testContext)