calling GORM methods in WebTest

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

calling GORM methods in WebTest

dkoo761
Hi everyone,

We're using Groovy/Grails with the WebTest plugin and have been pretty happy with this combo so far.

One thing that's slowing us down though is the amount of work required to setup a WebTest (ie. get the DB in a specific state) using ONLY WebTest steps (ie. clicking through our web app to create a certain type of user before we test something using that user). Often our setup steps out-number our testing steps and this makes our test suites slow and lengthy to run.

I've read that some people use dbunit and/or sqlunit to setup/teardown their DB inside a WebTest step, but since we're using Grails we'd rather not write direct SQL code if we don't have to (and there are other Java/Groovy classes we'd like to leverage in our setup/teardown).

Therefore, what we'd ideally like to do is do the setup/teardown in a Groovy step by calling Grails' GORM dynamic persistence methods such as MyClass.save(). I tried creating a simple 2-line groovy file as follows:

import org.mypackage.MyDomainClass
def someVar = MyDomainClass.findByName("John")

....but I got a run-time error that the property "MyDomainClass" could not be found, so it seems like WebTest is ignoring my import statement or can't find the class file? Has anyone else successfully imported classes into a groovy step? Eclipse resolves the import just fine at compile-time.

If it's not possible to import external classes or to use GORM in a Groovy step, then I does anyone know if it's possible to use GORM in a custom step? If not, then I guess we'll have to setup/teardown our data via dbunit or sqlunit but it would be a shame to have to bypass all the Grails goodness.

Thanks,
Dave
Reply | Threaded
Open this post in threaded view
|

Re: calling GORM methods in WebTest

Dierk König
Hi Dave,

remember that webtests run on the client side. You have no access to the
server other than through http.

Webtest is designed to do what otherwise a manual tester could do when
sitting in front of the browser.

That said, you could still use the <groovy> webtest step to connect to  
the
database (using GroovySQL or standalone GORM).

cheers
Dierk


Am 01.09.2009 um 20:34 schrieb dkoo761:

>
> Hi everyone,
>
> We're using Groovy/Grails with the WebTest plugin and have been  
> pretty happy
> with this combo so far.
>
> One thing that's slowing us down though is the amount of work  
> required to
> setup a WebTest (ie. get the DB in a specific state) using ONLY  
> WebTest
> steps (ie. clicking through our web app to create a certain type of  
> user
> before we test something using that user). Often our setup steps out-
> number
> our testing steps and this makes our test suites slow and lengthy to  
> run.
>
> I've read that some people use dbunit and/or sqlunit to setup/
> teardown their
> DB inside a WebTest step, but since we're using Grails we'd rather  
> not write
> direct SQL code if we don't have to (and there are other Java/Groovy  
> classes
> we'd like to leverage in our setup/teardown).
>
> Therefore, what we'd ideally like to do is do the setup/teardown in  
> a Groovy
> step by calling Grails' GORM dynamic persistence methods such as
> MyClass.save(). I tried creating a simple 2-line groovy file as  
> follows:
>
> import org.mypackage.MyDomainClass
> def someVar = MyDomainClass.findByName("John")
>
> ....but I got a run-time error that the property "MyDomainClass"  
> could not
> be found, so it seems like WebTest is ignoring my import statement  
> or can't
> find the class file? Has anyone else successfully imported classes  
> into a
> groovy step? Eclipse resolves the import just fine at compile-time.
>
> If it's not possible to import external classes or to use GORM in a  
> Groovy
> step, then I does anyone know if it's possible to use GORM in a  
> custom step?
> If not, then I guess we'll have to setup/teardown our data via  
> dbunit or
> sqlunit but it would be a shame to have to bypass all the Grails  
> goodness.
>
> Thanks,
> Dave
> --
> View this message in context: http://www.nabble.com/calling-GORM-methods-in-WebTest-tp25244273p25244273.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: calling GORM methods in WebTest

greggobridges
In reply to this post by dkoo761
You cannot access the domain classes from web tests.

I put the db setup stuff in Bootstrap.groovy with a check to see if the current environment is 'test'. Granted, it's not the same as being able to do setup/teardown, but it's better than nothing.

-Greg



----- Original Message ----
From: dkoo761 <[hidden email]>
To: [hidden email]
Sent: Tuesday, September 1, 2009 1:34:13 PM
Subject: [grails-user] calling GORM methods in WebTest


Hi everyone,

We're using Groovy/Grails with the WebTest plugin and have been pretty happy
with this combo so far.

One thing that's slowing us down though is the amount of work required to
setup a WebTest (ie. get the DB in a specific state) using ONLY WebTest
steps (ie. clicking through our web app to create a certain type of user
before we test something using that user). Often our setup steps out-number
our testing steps and this makes our test suites slow and lengthy to run.

I've read that some people use dbunit and/or sqlunit to setup/teardown their
DB inside a WebTest step, but since we're using Grails we'd rather not write
direct SQL code if we don't have to (and there are other Java/Groovy classes
we'd like to leverage in our setup/teardown).

Therefore, what we'd ideally like to do is do the setup/teardown in a Groovy
step by calling Grails' GORM dynamic persistence methods such as
MyClass.save(). I tried creating a simple 2-line groovy file as follows:

import org.mypackage.MyDomainClass
def someVar = MyDomainClass.findByName("John")

....but I got a run-time error that the property "MyDomainClass" could not
be found, so it seems like WebTest is ignoring my import statement or can't
find the class file? Has anyone else successfully imported classes into a
groovy step? Eclipse resolves the import just fine at compile-time.

If it's not possible to import external classes or to use GORM in a Groovy
step, then I does anyone know if it's possible to use GORM in a custom step?
If not, then I guess we'll have to setup/teardown our data via dbunit or
sqlunit but it would be a shame to have to bypass all the Grails goodness.

Thanks,
Dave
--
View this message in context: http://www.nabble.com/calling-GORM-methods-in-WebTest-tp25244273p25244273.html
Sent from the grails - user mailing list archive at Nabble.com.


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

    http://xircles.codehaus.org/manage_email

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: calling GORM methods in WebTest

dkoo761
Dierk - I had a funny feeling you'd say that :) It's good to know that standalone GORM is an option as that's something that we might look into.

Greg - we do the exact same thing for a bunch of our test data, but there are often tests that need the DB in a different state from the one Bootstrap sets it up in.

I think what we'll probably do for now if we need data in the DB that's specific to a particular test is to have a controller action that matches the test name which we can use to do the data loading via GORM. For example, if we have a webtest class called UserTest with a test case called testListUsers(), then we'd have a UserTestController (in a test package) with an action called testListUsers that would have the data loading/unloading logic in it. Then at the top of the testListUsers() method, we'd invoke "UserTestController/testListUsers?task=setup" to do the setup (and likewise with task=teardown for the teardown). It's a hack, but should do the trick :)

Cheers,
Dave

greggobridges wrote
You cannot access the domain classes from web tests.

I put the db setup stuff in Bootstrap.groovy with a check to see if the current environment is 'test'. Granted, it's not the same as being able to do setup/teardown, but it's better than nothing.

-Greg



----- Original Message ----
From: dkoo761 <dkoo@2paths.com>
To: user@grails.codehaus.org
Sent: Tuesday, September 1, 2009 1:34:13 PM
Subject: [grails-user] calling GORM methods in WebTest


Hi everyone,

We're using Groovy/Grails with the WebTest plugin and have been pretty happy
with this combo so far.

One thing that's slowing us down though is the amount of work required to
setup a WebTest (ie. get the DB in a specific state) using ONLY WebTest
steps (ie. clicking through our web app to create a certain type of user
before we test something using that user). Often our setup steps out-number
our testing steps and this makes our test suites slow and lengthy to run.

I've read that some people use dbunit and/or sqlunit to setup/teardown their
DB inside a WebTest step, but since we're using Grails we'd rather not write
direct SQL code if we don't have to (and there are other Java/Groovy classes
we'd like to leverage in our setup/teardown).

Therefore, what we'd ideally like to do is do the setup/teardown in a Groovy
step by calling Grails' GORM dynamic persistence methods such as
MyClass.save(). I tried creating a simple 2-line groovy file as follows:

import org.mypackage.MyDomainClass
def someVar = MyDomainClass.findByName("John")

....but I got a run-time error that the property "MyDomainClass" could not
be found, so it seems like WebTest is ignoring my import statement or can't
find the class file? Has anyone else successfully imported classes into a
groovy step? Eclipse resolves the import just fine at compile-time.

If it's not possible to import external classes or to use GORM in a Groovy
step, then I does anyone know if it's possible to use GORM in a custom step?
If not, then I guess we'll have to setup/teardown our data via dbunit or
sqlunit but it would be a shame to have to bypass all the Grails goodness.

Thanks,
Dave
--
View this message in context: http://www.nabble.com/calling-GORM-methods-in-WebTest-tp25244273p25244273.html
Sent from the grails - user mailing list archive at Nabble.com.


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

    http://xircles.codehaus.org/manage_email

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

    http://xircles.codehaus.org/manage_email