Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] Mocking

Alexandre Poitras

2008-09-02

Replies: Find Java Web Hosting

Author LoginPost Reply
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
©2008 gg3721.com - Jax Systems, LLC, U.S.A.