Grails Functional Testing - grailsApplication.config is null within controllers and services

时光毁灭记忆、已成空白 提交于 2019-12-29 06:31:08

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/4217276/grails-functional-testing-grailsapplication-config-is-null-within-controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!