使用ScalaTest / ScalaTestPlus在Play 2.5中使用MasterSuite

时间:2017-05-02 07:21:56

标签: scala playframework scalatest

我想创建一个MasterSuite Test类,它会创建一个Fakeapplication来让我的测试更快。

GuiceApplicationBuilder文档中的示例无法编译。我错过了一些神奇的进口吗?

import play.api.test._
import org.scalatest._
import org.scalatestplus.play._
import play.api.{ Play, Application }
import play.api.inject.guice._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

// This is the "master" suite
class NestedExampleSpec extends Suites(
  new OneSpec,
  new TwoSpec
) with GuiceOneAppPerSuite {
  // Override app if you need an Application with other than non-default parameters.
  def fakeApplication(): Application =
    new GuiceApplicationBuilder().configure(Map("ehcacheplugin" -> "disabled")).build()

}

// These are the nested suites
@DoNotDiscover class OneSpec extends FunSuite with ConfiguredApp
@DoNotDiscover class TwoSpec extends FunSuite with ConfiguredApp

1 个答案:

答案 0 :(得分:0)

起飞: 导入org.scalatestplus.play.guice.GuiceOneAppPerSuite ,至少对我来说没有在2.5.x中找到导入

正确的进口: 导入play.api.inject.guice.GuiceApplicationBuilder

隐含值:

implicit lazy val app: play.api.Application = new GuiceApplicationBuilder().configure().build()

implicit lazy val materializer: Materializer = app.materializer

运行a test suite in playFramework 2.5.x using it

的示例