所以我有这个测试(不幸的是我不能包含完整的代码,并且未能重现简化版本(:
"create method" should {
"return OK" in {
val offerService: OfferService = mock[OfferService]
(offerService.create _).expects(offer).returning(Future(Left(Created())))
val controller = new OfferController(offerService)
val request = FakeRequest(POST, "/offer").withJsonBody(Json.toJson(offer))
val result: Future[Result] = call(controller.create, request)
status(result) must be (201)
}
}
由于此错误而失败:
[info] create method
[info] - should return OK *** FAILED ***
[info] Unexpected call: <mock-1> OfferService.create(Offer(PixelSlate))
[info]
[info] Expected:
[info] inAnyOrder {
[info] <mock-1> OfferService.create(Offer(PixelSlate)) once (never called - UNSATISFIED)
[info] }
[info]
[info] Actual:
[info] <mock-1> OfferService.create(Offer(PixelSlate)) (Option.scala:121)
我在这里错过了一些明显的东西吗?模拟方法仅调用一次。为什么说该方法被调用然后没有同时调用?
没有足够的信息来回答为什么会发生这种情况。 您没有显示offer
是什么,但问题取决于该类型的==
契约是内容相等而不是引用相等。 如果该类型的行为很有趣,并且超出您的控制范围,请改用谓词匹配:https://scalamock.org/user-guide/matching/