无法解析playframework 2.6.17中的模拟[....]

时间:2018-08-13 06:45:11

标签: scala playframework

我想模拟ReactiveMongoAPI,为此,我正在编写以下代码,

package controllers

import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play._
import org.scalatestplus.play.guice._
import play.api.test.Helpers._
import play.api.test._
import play.modules.reactivemongo.ReactiveMongoApi


/**
 * Add your spec here.
 * You can mock out a whole application including requests, plugins etc.
 *
 * For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
 */
class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting with MockitoSugar {

  val reactiveMongoApi: mock[ReactiveMongoApi]

  "HomeController GET" should {

    "render the index page from a new instance of controller" in {


      val controller = new HomeController(stubControllerComponents(), reactiveMongoApi)
      val home = controller.index().apply(FakeRequest(GET, "/"))

它给我一个错误,它无法解决模拟[...]。 有什么办法解决这个问题?

1 个答案:

答案 0 :(得分:0)

我敢打赌,您想这样做:

val reactiveMongoApi: ReactiveMongoApi = mock[ReactiveMongoApi]