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-issuemaster opened this Issue Mar 15, 2008 · 9 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster 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:

  • #9917 Support loading WebApplicationContexts with the TestContext Framework ("depends on")
  • #9201 Autowiring won't work when using scopes and targetClass auto proxying
  • #14588 Introduce bootstrap strategy in the TestContext framework

Referenced from: commits a281bdb, 21ebbb9

11 votes, 12 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented 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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 27, 2008

David J. M. Karlsen commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented 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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented May 26, 2008

David J. M. Karlsen commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented 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=2

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented 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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster 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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 29, 2014

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-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 31, 2014

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