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
.
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'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With