Grails functional testing - grailsApplication.config is null in controllers and services

Grails 1.3.5

I have written several functional tests, and I am having problems when my controllers and services reference configuration data via grailsApplication.config. It always returns zero, so it is wrong.

I know that for unit tests there is mockConfig. But how do I get the configuration to connect to functional tests?

+3
source share
2 answers

This is the hack I did for a while, maybe better 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 
+5
source

You need to build a grails application - as it is not entered by default.

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

"DefaultGrailsApplication" by default will look for Config as a configuration class.

+13
source

Source: https://habr.com/ru/post/1345581/


All Articles