Mocking configuration in Grails unit tests
by Vladimir Grichina
While testing some of the classes in Grails app, I had problem that the tests failed because Grails config (
ConfigurationHolder.config) isn’t populated (is
null) when unit tests are executed. Some Googling found me issue in JIRA which explained it.
Graeme Rocher commented that there is
mockConfig method which allows to specify mocked config to be used for tests. It can be called in
setUp method to do necessary initialization.
It is convenient to use it with multi-line strings. Its usage goes as following:
mockConfig ''' foo.bar = "good" '''
It is discussed in more details in mrhaki's post.
We develop mobile and web apps, you can hire us to work on your next project.