所以我有这个测试(很遗憾,我无法包含完整的代码,并且无法复制简化的版本):
"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)
我在这里缺少明显的东西吗?模拟方法仅被调用一次。为什么说该方法先被调用然后又未被调用?
答案 0 :(得分:0)
信息不足,无法回答为什么会发生这种情况。
您没有显示offer
是什么,但是问题取决于这种类型的==
合同,即内容平等而不是引用平等。
如果该类型的行为很有趣,并且超出了您的控制范围,请改用谓词匹配:https://scalamock.org/user-guide/matching/