【问题标题】:MasterSuite in Play 2.5 with ScalaTest / ScalaTestPlus带有 ScalaTest / ScalaTestPlus 的 Play 2.5 中的 MasterSuite
【发布时间】:2023-03-06 03:17:01
【问题描述】:

我想创建一个 MasterSuite 测试类,该类创建一个 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

【问题讨论】:

  • 似乎是一个错误的文档。现在一切正常,如果我使用 override lazy val app:Application 而不是 def fakeApplication():Application 配置应用程序

标签: scala playframework scalatest


【解决方案1】:

起飞: import org.scalatestplus.play.guice.GuiceOneAppPerSuite,至少对我来说在 play 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的例子

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多