[Functional Testing] Two Sessions?

View: New views
6 Messages — Rating Filter:   Alert me  

[Functional Testing] Two Sessions?

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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?

[1] Grails Functional Test plugin

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

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

    http://xircles.codehaus.org/manage_email



Re: [Functional Testing] Two Sessions?

by Marc Palmer Local :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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



Re: [Functional Testing] Two Sessions?

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That'd work.

The approach I was thinking about was userA.get("/messages"), userB.post("/messages"), etc., etc.,
with a forClient(client) { ... } structure for grouping together multiple actions.  My usage is
going to involve a lot of switching back and forth, so explicit lines switching clients is a bit chatty.

~~ Robert.

Marc Palmer 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
>
>
>

--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

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

    http://xircles.codehaus.org/manage_email



Re: [Functional Testing] Two Sessions?

by Edward Sumerfield-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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




Re: [Functional Testing] Two Sessions?

by Marc Palmer Local :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2 Jul 2009, at 18:43, Edward Sumerfield wrote:

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

No this is functional testing with grails-functional-test plugin - no  
mocking possible.

~ ~ ~
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



Re: [Functional Testing] Two Sessions?

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Of course, if you create your version, I can create mine from it.  :)

~~ Robert.

Robert Fischer wrote:

> That'd work.
>
> The approach I was thinking about was userA.get("/messages"),
> userB.post("/messages"), etc., etc., with a forClient(client) { ... }
> structure for grouping together multiple actions.  My usage is going to
> involve a lot of switching back and forth, so explicit lines switching
> clients is a bit chatty.
>
> ~~ Robert.
>
> Marc Palmer 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
>>
>>
>>
>

--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html

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

    http://xircles.codehaus.org/manage_email