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
Provide support for session/request scoped beans for integration testing [SPR-4588] #9265
has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importin: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement
It would be very handy if Spring could provide support for session and request scoped beans for integration testing (e.g. in the TestContext framework).
GitHub commit 21ebbb9c02 introduces RequestAndSessionScopedBeansWacTests which verifies support for request and session scoped beans in the Spring TestContext Framework (TCF).
This support was actually introduced as an intentional side effect of the work performed for #9917 through the addition of the new ServletTestExecutionListener.
Attached file has non-static @BeforeClass method, which JUnit 4.11 doesn't accept. But it's not possible to make it static, because it uses non-static applicationContext.
Dzmitry Lazerka, that's correct: the code in the AbstractJUnit4SpringWebContextTests attachment does not work, but fear not: this issue was resolved in October 2013. Thus, there is no need for such custom solutions beginning with Spring Framework 3.2.
has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importin: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement
Activity
spring-projects-issues commentedon Mar 15, 2008
David J. M. Karlsen commented
There's also a thread on the forum related to this: http://forum.springframework.org/archive/index.php/t-40257.html .
We're getting around it by using a prototype instead during testing (or just inserting a bean ourselves) - but I'd prefer a OOTB solution.
spring-projects-issues commentedon Mar 27, 2008
David J. M. Karlsen commented
Did I hear a fix-version 2.5.3? ;-)
spring-projects-issues commentedon Apr 23, 2008
David J. M. Karlsen commented
This discussion is relevant and points on some ways to solve this: http://forum.springframework.org/showthread.php?t=27933
spring-projects-issues commentedon May 26, 2008
David J. M. Karlsen commented
Attached is a somewhat naive approach which could be further refined.
spring-projects-issues commentedon Aug 24, 2009
Stefan Scheidt commented
There's a forum thread showing a solution that works with Spring TestContext and uses a custom context loader in
@ContextConfiguration, see: http://forum.springsource.org/showthread.php?t=50722&page=2spring-projects-issues commentedon May 25, 2011
Morten Andersen-Gott commented
Spring Batch uses a custom TestExecutionListener to test step scoped components: http://static.springsource.org/spring-batch/reference/html-single/index.html#d0e7538 A similar approach for session and request scopes would make sense?
spring-projects-issues commentedon Oct 13, 2012
Sam Brannen commented
GitHub commit 21ebbb9c02 introduces
RequestAndSessionScopedBeansWacTestswhich verifies support for request and session scoped beans in the Spring TestContext Framework (TCF).This support was actually introduced as an intentional side effect of the work performed for #9917 through the addition of the new
ServletTestExecutionListener.spring-projects-issues commentedon Jan 29, 2014
Dzmitry Lazerka commented
Attached file has non-static
@BeforeClassmethod, which JUnit 4.11 doesn't accept. But it's not possible to make it static, because it uses non-static applicationContext.spring-projects-issues commentedon Jan 31, 2014
Sam Brannen commented
Dzmitry Lazerka, that's correct: the code in the
AbstractJUnit4SpringWebContextTestsattachment does not work, but fear not: this issue was resolved in October 2013. Thus, there is no need for such custom solutions beginning with Spring Framework 3.2.Please see the Testing request and session scoped beans section of the reference manual for details.
Regards,
Sam