Grails功能测试 - 控制器和服务中的grailsApplication.config为null [英] Grails Functional Testing - grailsApplication.config is null within controllers and services

查看:94
本文介绍了Grails功能测试 - 控制器和服务中的grailsApplication.config为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Grails 1.3.5

Grails 1.3.5

我写了一些功能测试,当我的控制器和服务通过grailsApplication.config引用配置数据时遇到问题。它总是返回null,所以它出错。

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.

我知道有单元测试的mockConfig。但是,如何获取配置以进行功能测试?

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

推荐答案

这是我为虽然可能有更好的办法,但是

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

这篇关于Grails功能测试 - 控制器和服务中的grailsApplication.config为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆