You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Introduce autowiring support for the current TestContext [SPR-8299] #12947
Tests currently do not have access to the current TestContext.
Providing access to the TestContext would allow programmatic access to TestContext properties as well as methods such as markApplicationContextDirty().
Considerations
Instead of exposing the TestContextas is, it may be preferential to expose a new (yet-to-be-implemented) public-facing interface that defines a subset of the publicly available methods in TestContext.
A similar approach could be introduced to provide programmatic support for transaction management.
Code Samples
DependencyInjectionTestExecutionListener's injectDependencies(TestContext) method could be modified as follows:
protectedvoidinjectDependencies(finalTestContexttestContext) throwsException {
Objectbean = testContext.getTestInstance();
ApplicationContextapplicationContext = testContext.getApplicationContext();
// BEGIN NEW CODE// Enable autowiring of the current TestContext.if (applicationContextinstanceofConfigurableApplicationContext) {
ConfigurableApplicationContextconfigurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
configurableApplicationContext.getBeanFactory().registerResolvableDependency(TestContext.class, testContext);
}
// END NEW CODEAutowireCapableBeanFactorybeanFactory = applicationContext.getAutowireCapableBeanFactory();
beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
beanFactory.initializeBean(bean, testContext.getTestClass().getName());
testContext.removeAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE);
}
Activity
sbrannen commentedon Feb 23, 2019
Closing this issue due to lack of interest from the community.