我无法使用Specs2和Mockito运行我的Scala单元测试。
val response = mock[Response]
"MyResource" should {
"handle NOT_FOUND from another WS" in {
response.status returns NOT_FOUND // Exception thrown here
anotherWS.getDetails("101010", "101") returns Future.successful(response)
.....
}
例外:
org.mockito.internal.invocation.Invocation.isToString(Lorg/mockito/invocation/InvocationOnMock;)Z
org.specs2.execute.Error$ThrowableException: NoSuchMethodError: org.mockito.internal.invocation.Invocation.isToString(Lorg/mockito/invocation/InvocationOnMock;)Z
Caused by: java.lang.NoSuchMethodError: org.mockito.internal.invocation.Invocation.isToString(Lorg/mockito/invocation/InvocationOnMock;)Z
at org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues.answer(ReturnsEmptyValues.java:59)
at org.mockito.internal.stubbing.defaultanswers.GloballyConfiguredAnswer.answer(GloballyConfiguredAnswer.java:24)
at org.mockito.internal.MockHandler.handle(MockHandler.java:99)
at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:47)
答案 0 :(得分:1)
更新到mockito 1.9.5(使用1.8.5)修复了问题
答案 1 :(得分:0)
Mockito不支持模拟变量。 status
对象上的response
是变量吗?如果是这样,一个解决方案是定义一个getStatus()方法,然后模拟该方法。