3 Replies Latest reply on Feb 24, 2009 7:02 AM by ssilvert

    JSFUnit design??

    dareurdream

      Hi,

      I was debugging one of my jsfunit test class, when I found that jsfunit calls the setUp() function(where it gets a handle of the jsfsession) before every test function execution. What I mean to say is - If have 7 test functions A,B,...G; then setUp() is called before the execution of A() (Which is absolutely correct as it has to get handle of jsfsession). Setup() is again called before the execution of B(), again before the execution of C() and soon.

      I believe that the jsfsession is synchronized automatically as and when there are any changes. Is that so? Is it correct that setUp has to be called so many times? Is it a issue or there is some other logic behind it.

      Manish

        • 1. Re: JSFUnit design??
          ssilvert

          setUp() is called before each test method. That is part of the JUnit TestCase API, so it is not something that JSFUnit has control of.

          JSFUnit does control what happens when you create a new JSFSession. When a new JSFSession is created, the HttpSession is cleared and you are given a "fresh" browser instance from HtmlUnit. So you are in a state where you are a new user sending an initial request to your application. Most of the time that is what you want when you start a new test.

          If you want to continue the same user session then code your test class so that it only has one test method:

          public class MyTest extends ServletTestCase
          {
           private JSFClientSession client;
           private JSFServerSession server;
          
           public void setUp() throws IOException
           {
           JSFSession jsfSession = new JSFSession("/index.faces");
           this.client = jsfSession.getJSFClientSession();
           this.server = jsfSession.getJSFServerSession();
           }
          
           public static Test suite()
           {
           return new TestSuite( MyTest.class );
           }
          
           public void testAlotOfStuffInASingleSession() throws IOException
           {
           stuff1();
           stuff2();
           stuff3();
           }
          
           public void stuff1() throws IOException {// more testing goes here}
           public void stuff2() throws IOException {// more testing goes here}
           public void stuff3() throws IOException {// more testing goes here}
          }


          Just don't start your "stuff" methods with the word "test". If you do, JUnit will call setUp() and then call that method.

          Stan

          • 2. Re: JSFUnit design??
            dareurdream

            Hi Stan,

            Thanks for the clarification.

            Can you also clarify the other doubt:-

            I believe that the jsfsession is synchronized automatically as and when there are any changes. Is that so?


            Manish

            • 3. Re: JSFUnit design??
              ssilvert

              There are no synchronized methods in JSFSession, JSFClientSession, or JSFServerSession. But I'm not sure if that's what you mean.

              JSFSession is a session in the truest sense. If your browser view changes then you are going to be looking at the new page just as if you were a user.

              Stan