问题描述
在Grails 2.0.X之前,可以使用由测试扩展的基类提供的 mockConfig
方法来模拟配置。但是,在Grails 2.0.X中,建议测试类使用 @TestFor
mixin代替扩展基类。
这个mixin似乎没有提供任何相当于 mockConfig
方法的东西,所以我无法弄清楚如何模拟 Config中的值.groovy
。
您可以访问grailsApplication.config,以便尽可能多地修改这些值如你所需,所以你可以这样做
$ b $ pre $ g $ grailsApplication.config.some.config.setting ='foo'
Prior to Grails 2.0.X it was possible to mock configuration using a mockConfig
method provided by the base class that tests extend. However, in Grails 2.0.X it is recommended that test classes use the @TestFor
mixin instead of extending a base class.
This mixin doesn't seem to provide anything equivalent to the mockConfig
methods, so I can't figure out how to mock values in Config.groovy
.
You have access to grailsApplication.config so you can modify these values as much as you need, so you can do
grailsApplication.config.some.config.setting = 'foo'
这篇关于在Grails测试中进行模拟配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!