Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide support for session/request scoped beans for integration testing [SPR-4588] #9265

Closed
spring-projects-issues opened this issue Mar 15, 2008 · 9 comments
Assignees
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 15, 2008

David J. M. Karlsen opened SPR-4588 and commented

Overview

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).

Further Resources


Affects: 2.5.2

Attachments:

Issue Links:

Referenced from: commits a281bdb, 21ebbb9

11 votes, 12 watchers

@spring-projects-issues
Copy link
Collaborator Author

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
Copy link
Collaborator Author

David J. M. Karlsen commented

Did I hear a fix-version 2.5.3? ;-)

@spring-projects-issues
Copy link
Collaborator Author

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
Copy link
Collaborator Author

David J. M. Karlsen commented

Attached is a somewhat naive approach which could be further refined.

@spring-projects-issues
Copy link
Collaborator Author

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=2

@spring-projects-issues
Copy link
Collaborator Author

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
Copy link
Collaborator Author

spring-projects-issues commented Oct 13, 2012

Sam Brannen commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Dzmitry Lazerka commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

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.

Please see the Testing request and session scoped beans section of the reference manual for details.

Regards,

Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants