Spring Framework
  1. Spring Framework
  2. SPR-4588

Provide support for session/request scoped beans for integration testing

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 2.5.2
    • Fix Version/s: 3.2 RC1
    • Component/s: Test, Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      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

        Issue Links

          Activity

          Hide
          David J. M. Karlsen added a comment -

          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.

          Show
          David J. M. Karlsen added a comment - 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.
          Hide
          David J. M. Karlsen added a comment -

          Did I hear a fix-version 2.5.3?

          Show
          David J. M. Karlsen added a comment - Did I hear a fix-version 2.5.3?
          Hide
          David J. M. Karlsen added a comment - - edited

          This discussion is relevant and points on some ways to solve this: http://forum.springframework.org/showthread.php?t=27933

          Show
          David J. M. Karlsen added a comment - - edited This discussion is relevant and points on some ways to solve this: http://forum.springframework.org/showthread.php?t=27933
          Hide
          David J. M. Karlsen added a comment -

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

          Show
          David J. M. Karlsen added a comment - Attached is a somewhat naive approach which could be further refined.
          Hide
          Stefan Scheidt added a comment -

          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

          Show
          Stefan Scheidt added a comment - 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
          Hide
          Morten Andersen-Gott added a comment -

          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?

          Show
          Morten Andersen-Gott added a comment - 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?
          Hide
          Sam Brannen added a comment - - edited

          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 SPR-5243 through the addition of the new ServletTestExecutionListener.

          Show
          Sam Brannen added a comment - - edited 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 SPR-5243 through the addition of the new ServletTestExecutionListener .
          Hide
          Dzmitry Lazerka added a comment -

          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.

          Show
          Dzmitry Lazerka added a comment - 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.
          Hide
          Sam Brannen added a comment -

          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

          Show
          Sam Brannen added a comment - 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

            People

            • Assignee:
              Sam Brannen
              Reporter:
              David J. M. Karlsen
              Last updater:
              Sam Brannen
            • Votes:
              11 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                11 weeks, 4 days ago

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 0.5d
                0.5d