Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Mar 15, 2008

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. spring-projects-issues commented on Mar 27, 2008

    @spring-projects-issues
    CollaboratorAuthor

    David J. M. Karlsen commented

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

  3. spring-projects-issues commented on May 26, 2008

    @spring-projects-issues
    CollaboratorAuthor

    David J. M. Karlsen commented

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

  4. spring-projects-issues commented on Aug 24, 2009

    @spring-projects-issues
    CollaboratorAuthor

    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

  5. spring-projects-issues commented on May 25, 2011

    @spring-projects-issues
    CollaboratorAuthor

    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?

  6. spring-projects-issues commented on Oct 13, 2012

    @spring-projects-issues
    CollaboratorAuthor

    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.

  7. spring-projects-issues commented on Jan 29, 2014

    @spring-projects-issues
    CollaboratorAuthor

    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.

  8. spring-projects-issues commented on Jan 31, 2014

    @spring-projects-issues
    CollaboratorAuthor

    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

  9. added
    in: test
    type: enhancement
    has: votes-jira
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

has: votes-jirain: testin: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions