Alexandre Poitras | 2 Sep 22:03

[groovy-user] Mocking

Hi

We are using Grails on a project and I was wondering how do you guys mock Grails static methods in Groovy? We used to use the object metaClass property to inject the desired behaviour in a collaborator but unfortunately we quickly found out it wasn't a great idea since all changes made throught the metaClass are global and not local to the test. This can cause a lot of side effects on subsequent tests as we have experienced.

Right now, I'm thinking of hiding all these methods behind a repository interface as we are used to do in Java. It may requires some boilerplate code but at least it is testable.

Am I missing something? Any suggestions?

Alexandre Poitras
Graeme Rocher | 2 Sep 23:05
Gravatar

Re: [groovy-user] Mocking

You should probably be posting to the Grails list, but there are three ways.

a) Write an integration test, in which case all the methods are there
b) Mock them using metaprogramming
c) Try out the testing plugin (grails install-plugin) which provides a
MockUtils class and various mocking support super classes

Cheers

On Tue, Sep 2, 2008 at 9:05 PM, Alexandre Poitras
<apoitras@...> wrote:
> Hi
>
> We are using Grails on a project and I was wondering how do you guys mock
> Grails static methods in Groovy? We used to use the object metaClass
> property to inject the desired behaviour in a collaborator but unfortunately
> we quickly found out it wasn't a great idea since all changes made throught
> the metaClass are global and not local to the test. This can cause a lot of
> side effects on subsequent tests as we have experienced.
>
> Right now, I'm thinking of hiding all these methods behind a repository
> interface as we are used to do in Java. It may requires some boilerplate
> code but at least it is testable.
>
> Am I missing something? Any suggestions?
>
> Alexandre Poitras
>

--

-- 
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.com

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

    http://xircles.codehaus.org/manage_email


Gmane