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

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

问题描述

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.

我知道有一个用于单元测试的模拟配置.但是我如何获得配置以进行功能测试?

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

推荐答案

这是我做了一段时间的 hack,不过可能有更好的方法

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 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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