unit-testing - 在 grails 2.2.3 单元测试中使用多个 mockFor()
问题描述
我想为我的控制器编写一个单元测试,它在其中使用多个服务。如何将多个 mockFor() 用于服务?肿瘤坏死因子。
解决方案
例如使用 spock 进行测试:
class ExampleControllerUnitSpec extends Specification {
def anyService
def anotherService
def setup() {
anyService = Mock(AnyService)
controller.anyService = anyService
anotherService = Mock(AnotherService)
controller.anotherService = anotherService
}
def "test"(){
when:
controller.action()
then:
1 * anyService.doSomething() >> "result"
3 * anotherService.doSomethingElse() >> "result2"
}
}
推荐阅读
- javascript - 浏览器通知 onclick 事件不会在 chrome 中触发
- java - RepositoryRestExceptionHandler :对象不是托管实体
- c# - 以编程方式更改 WPF Datagrid Row 背景颜色
- numpy - 如何将二维数组从较粗的分辨率插入到较细的分辨率
- mongodb - Mongoose 在 findByIdAndUpdate() 上将所有嵌套字段更新为 null
- javascript - 多个过滤器,一个 onChange 函数
- html - 为什么单击 2 次后更新面板正常工作
- angularjs - AngularJS 发布 sitemap.xml
- arrays - 如何在VB中附加一个二维数组和一个一维数组?
- c++ - C++ 程序太慢而且似乎不起作用?