other register

Thursday, September 15, 2011

Mock grailsApplication and config in Unit Test

grailsApplication can be injected in controller before 2.0.0, and it is still the case for 2.0.0

Before grails 2.0.0, you can only access your config in the service by calling ConfigurationHolder.config. But now with Grails 2.0.0, grailsApplication can be injected in service.

In unit test, we should do the following, so that the grailsApplication and config is mocked properly.

service.grailsApplication = [config.config]

controller.grailsApplication = [config: config]

No comments: