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
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);
}
Sam Brannen opened SPR-8299 and commented
Status Quo
Tests currently do not have access to the current
TestContext
.Providing access to the
TestContext
would allow programmatic access toTestContext
properties as well as methods such asmarkApplicationContextDirty()
.Considerations
Instead of exposing the
TestContext
as 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 inTestContext
.A similar approach could be introduced to provide programmatic support for transaction management.
Code Samples
DependencyInjectionTestExecutionListener
'sinjectDependencies(TestContext)
method could be modified as follows:Affects: 2.5.6
Issue Links:
The text was updated successfully, but these errors were encountered: