« Return to Thread: [Functional Testing] Two Sessions?

Re: [Functional Testing] Two Sessions?

by Edward Sumerfield-2 :: Rate this Message:

Reply to Author | View in Thread

Since Controller tests mock the session can't you just switch between two sessions between calls to your controller?

So, in MockUtils.addCommonWebProperties the MockHttpSession is created then made available to the controller through

            clazz.metaClass.getSession = {-> mockSession}

So, all you could emulate two sessions with

    def session1 = controller.session
    def session2 = new MockHttpSession()

    controller.call_action()

    controller.metaClass.getSession = {-> session2 }

    controller.call_action()

    controller.metaClass.getSession = {-> session1 }

and so on.

On Thu, Jul 2, 2009 at 12:39 PM, Marc Palmer <marc@...> wrote:

On 2 Jul 2009, at 15:42, Robert Fischer wrote:

I'm testing an interactive feature of my app, and I want to use g-func[1] to test it.  This means I need to have two sessions on at the same time, so that when one does something, I can check for a change in the other.  Is there an easy way to do this that I'm missing?


Not currently no.

Depending on what is a reasonable feature need, there are a couple of ways to cut it.

For example, I think we would probably be able to swap out the HtmlUnit webclient for a new one mid-test, and pull back the other one by name. This effectively gives you separate browsers / sessions.

Another way would be to pull out pretty much everything from FunctionalTestCase into a FunctionTestClient that you can have multiple of and the test case class would just manage the "current" one and delegate all calls to it.

If the interaction you want to test is something like:

1. User A submits a chat message
2. User B refresh chat to see user A's message
3. User B submits reply chat message
4. User A refreshes to see B's message

Then I think this is still well within the ethos of G-Func as it is nicely linear and the tests remain easy to grok etc.

We could implement that quite simply I think, something like:

client "User A"

get("/messages")

client "User B"

post('/messages') { .... }

client "User A"


Eg the client method just switches to a named client.

Marc

~ ~ ~
Marc Palmer
Blog         > http://www.anyware.co.uk
Twitter      > http://twitter.com/wangjammer5
Grails Rocks > http://www.grailsrocks.com








---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



 « Return to Thread: [Functional Testing] Two Sessions?