Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mock configuration in Grails tests

Prior to Grails 2.0.X it was possible to mock configuration using a mockConfig method provided by the base class that tests extend. However, in Grails 2.0.X it is recommended that test classes use the @TestFor mixin instead of extending a base class.

This mixin doesn't seem to provide anything equivalent to the mockConfig methods, so I can't figure out how to mock values in Config.groovy.

like image 877
Dónal Avatar asked May 24 '12 20:05

Dónal


2 Answers

You have access to grailsApplication.config so you can modify these values as much as you need, so you can do

grailsApplication.config.some.config.setting = 'foo'
like image 92
Fran García Avatar answered Oct 11 '22 00:10

Fran García


I'm doing it this way (in the case when I'm testing a service):

service.grailsApplication.config.mysetting = 'my value'
def result = service.myMethod()
// check results

No other mocking required.

like image 41
tim_wonil Avatar answered Oct 11 '22 02:10

tim_wonil