在 Grails 3.2.x 和更早的版本中,我可以在 spock 单元测试中做这样的事情:
def myServiceMock = Mock(MyService) {
someMethod() >> 42
}
Closure doWithSpring() {{ ->
myService(InstanceFactoryBean, myServiceMock, MyService)
}}
def "some test"(){
expect:
service.myService.someMethod() == 42
}
这将使模拟能够注入协作类中。
请参阅:http : //docs.grails.org/3.2.4/guide/testing.html 在“doWithSpring 和 doWithConfig 回调方法,FreshRuntime 注释”部分下。
在 Grails 3.3.2 中,它似乎不再起作用了。并且已经从测试文档中删除了它的提及。
有没有办法再次完成这种行为?
提前谢谢了!
/布莱恩