【发布时间】:2017-04-19 00:53:41
【问题描述】:
这就是我模拟我的服务调用并返回虚假结果的方式:
when(myService.doSomething("",fakeRequestAsModel)) thenReturn fakeResult
val result = call(controller.myActionMethod(), request)
问题出在控制器方法myActionMethod 中,当我调用doSomething 并传递参数即时调用某些属性时,该属性只会返回生产中的某些内容...
def myActionMethod() ... = {
myService.doSomething(request.getSomeValue,requestAsModel)
...
}
所以,getSomeValue 是一种我只能在生产中调用的方法,它带有一个 3rd 方库,我无法覆盖它。
我怎样才能模拟这个调用,所以request.getSomeValue 不会抛出异常?
而request.getSomeValue 是动态的,不幸的是我无法将其放入配置中...
【问题讨论】:
标签: scala mocking mockito scalatest