1 Reply Latest reply on Mar 8, 2018 11:36 AM by Morgan Pittkin

    Accessing @SessionScoped bean across tests

    Morgan Pittkin Newbie

      I'm having a problem with accessing a @SessionScoped bean across tests. The Arquillian documentation states that session and application scopes are active across all tests, and request scope for individual tests, which I took to mean that if I set some state in an injected @SessionScoped bean in one test method, then in the next test method I should see that state.


      I have a simple @SessionScoped bean called Session, which holds the current logged-in user information.


      I have injected it into an Arquillian test, and in one test method, I log the user in. That info is now stored in my Session bean.


      I would expect that the next test would see that same state (in this case, the user that I logged in in the first test), but I am seeing a fresh Session bean for every test.


      I have annotated the methods using @InSequence to ensure the correct order of execution (and verified with debugger).



      private Session session;



      @Test(expected = IllegalStateException.class)


      public void noLoggedInUser()


      log.info("First test");

      assertEquals(false, session.isLoggedIn());







      public void testLogin() throws AuthenticationException


      session.logIn("admin", "admin", null);


      assertEquals(true, session.isLoggedIn());






      public void testSessionAcrossRequests()


      assertTrue("Session should still be logged in", session.isLoggedIn());



      I don't know if this is a bug, a configuration problem, or me simply misreading the documentation.


      Any ideas?


      Thank you,



      PS If you can help me with this, I have a question unanswered on StackOverflow with your name on it:


        • 1. Re: Accessing @SessionScoped bean across tests
          Morgan Pittkin Newbie

          I finally noticed the mention of weld embedded container in the documentation that talks about active scopes in tests. After some wrangling with the wrong maven dependency for that, I finally got an example working with the weld embedded container 1.1, and in that case it works. So it seems it only works with that particular container? That would be a pretty nice thing to have working with other containers, is that not technically feasible?


          It seems like it would severely limit the usefulness of that particular feature, because if you want to run tests across different containers, a test that depends on that behavior will fail for all containers except the embedded weld container. Am I correct in thinking that?