1

我在使用 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)
4

2 回答 2

1

更新到 mockito 1.9.5(正在使用 1.8.5)解决了这个问题

于 2013-10-26T17:07:40.333 回答
0

Mockito 不支持模拟变量。对象上是否status有变量response?如果是这样,一种解决方案是定义一个 getStatus() 方法,然后模拟该方法。

于 2013-10-25T23:33:27.320 回答