3

Grails 1.3.5

I've written a handful of functional tests and I'm running into issues when my controllers and services reference configuration data via grailsApplication.config. It is always coming back null, so it errors out.

I know there is a mockConfig for unit tests. But how do I get the config to get wired up for functional tests?

Gregg
  • 34,973
  • 19
  • 109
  • 214

2 Answers2

13

You need to construct the grails app -- as it is not injected by default.

youService.grailsApplication = new org.codehaus.groovy.grails.commons.DefaultGrailsApplication()

"DefaultGrailsApplication" by it's default configuration will look for Config as the config class.

Macmade
  • 52,708
  • 13
  • 106
  • 123
Keith
  • 131
  • 1
  • 3
5

This is the hack that I have done for a while, there might be a better way though

def filePath = new File('grails-app/conf/Config.groovy').toURL()
def config = new ConfigSlurper(System.properties.get('grails.env')).parse(filePath)
ConfigurationHolder.config = config
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80