Thursday 10 January 2013

Grails: Testing classes in src/groovy

I spent some time today creating an annotation parsing that lives in src/groovy of a Grails application. I wanted to unit test it to ensure the behavior is correct. Since it's not a controller or service or a domain class, the following steps were required to make it work.

1.) Create the test under test/unit/{package}/{class under test}Tests
2.) Make sure the test class extends GroovyTestCase (a built in base class in Groovy)
3.) Also, make sure that the file name matches the class name (unlike Java, Groovy classes don't have to match the file name).

Once you have those requirements then you can run your tests just like any other Grails context aware classes.

No comments:

Post a Comment