0
のでscalatestplusプレイで作業していない:MockitoのScalaの検証は、私はスカラ座を使用してプレイ2.5のプロジェクトを持っている、と私は私のbuild.sbtにこれらの依存関係を持って、
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
"org.mockito" % "mockito-all" % "1.10.19" % Test
そして、私のテストでは、次のようになります。
import java.util.UUID
import org.mockito.Mockito._
import org.scalatest.BeforeAndAfter
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.mvc.{AnyContentAsEmpty, Result}
import play.api.test.{FakeRequest, Helpers}
import play.api.test.Helpers._
import services.TargetServiceImpl
import scala.concurrent.Future
class MyControllerTest extends PlaySpec with MockitoSugar with BeforeAndAfter with OneAppPerSuite {
val targetService = mock[TargetServiceImpl]
var subject = new TargetAjaxController(targetService)
"TargetAjaxController" should {
"use the mocked service to delete a target" in {
val oauthToken = UUID.randomUUID().toString
val targetId = Random.nextLong()
val result: Future[Result] = subject.delete(targetId).apply(fakeRequestWithSession(oauthToken))
verify(targetService).deleteTarget(targetId, oauthToken)
status(result) mustBe OK
contentType(result) mustBe Some("application/json")
}
}
private def fakeRequestWithSession(oauthToken: String): FakeRequest[AnyContentAsEmpty.type] = {
FakeRequest(Helpers.DELETE, "/targets")
.withSession(
("token", oauthToken)
)
}
}
私はこのテストを実行すると、私はというエラーメッセージが出ます:
org.mockito.exceptions.verification.WantedButNotInvoked: Wanted but not invoked (...) Actually, there were zero interactions with this mock
しかし、私は内一部のprintln年代を置くを、私はコードが実際に期待通りに実行され、モックが呼び出されたことをコンソールに表示しています.Mockitoはモックの使用状況を記録していません。
デベロッパーマシンで正常に動作するというのは、Jenkinsで実行された場合にのみエラーが発生することです。
ここで何か間違っていますか? verify
コールが機能しない理由は何ですか?
ありがとうございます!