Quantcast

Mock grailsApplication.config for service test

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Mock grailsApplication.config for service test

humpy125
I have a service I want to run some unit tests on. This service uses the grailsApplication.config to get some values. I was wondering how to mock this in Grails 2.0.4?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Mock grailsApplication.config for service test

bksaville
If you are using the TestFor annotation, there is already a grailsApplication variable available in the unit test you can modify that is also injected into the service.  i.e.

import grails.test.mixin.TestFor

@TestFor(MyService)
class MyServiceTests {
  void testMyService() {
    grailsApplication.config.my.service.property = true
    assert service.getMyConfigProperty()==true
  }
}

On Fri, Jul 6, 2012 at 12:28 AM, humpy125 <[hidden email]> wrote:
I have a service I want to run some unit tests on. This service uses the
grailsApplication.config to get some values. I was wondering how to mock
this in Grails 2.0.4?



--
View this message in context: http://grails.1312388.n4.nabble.com/Mock-grailsApplication-config-for-service-test-tp4631164.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Mock grailsApplication.config for service test

humpy125
Hi thanks for that. It got me on the right track.
Loading...