1
使用Spock(0.7)Grails(2.1.2)插件,您可以编写自动注入Grails原型(如服务)的集成规范。不过,我想为Spring beans做同样的事情,只在我的resources.groovy
中声明。例如:如何自动将resources.groovy中声明的Grails组件注入到我的IntegrationSpecs中?
beans = {
simpleBean(SimpleBean) {
// load some dependencies
}
}
其中SimpleBean在src/groovy
文件夹中声明。如果这是一个Grails服务,我可以写像下面这样在我test/integration
文件夹::
import grails.plugin.spock.IntegrationSpec
class SimpleBeanSpec extends IntegrationSpec {
def simpleBean
def "should"() {
when:
data = simpleBean.load()
then:
assert simpleBean
}
}
但上面的呼叫simpleBean.load()
抛出一个NullPointerException
。有什么方法可以让Spock/Grails创建simpleBean依赖关系,以便像Grails服务一样从resources.groovy
获得所有已配置的依赖关系?
测试是在测试/集成,我会更新问题来反映,但这绝对不适用于我的安装Grails。 –