Scala:游戏无法识别测试内容

问题描述 投票:0回答:1

我正在从Java过渡到Scala。我写了一个简单的测试来渲染视图。喜欢:

import org.scalatestplus.play.PlaySpec
import org.scalatest._
import org.slf4j.LoggerFactory
import play.test.WithApplication


class EvTemplateTests extends PlaySpec{
  implicit lazy val log = LoggerFactory.getLogger(getClass)

 //run your test//run your test

 "render eval template" in {
  val html = views.html.index("Hello")
  contentType(html) must equalTo("text/html")
  contentAsString(html) must contain("Welcome to Play!")
 }
}

[编译时,看起来好像找不到“ index”,“ contentType”,“ contentAsString”等。该项目正在使用库:

lazy val thirdPartyDependencies = Seq(
jdbc,
"com.typesafe.play" %% "anorm" % "2.4.0",
"com.typesafe.play" %% "play-mailer" % "3.0.1",
"com.microsoft.sqlserver" % "mssql-jdbc" % "6.4.0.jre8",
"io.swagger" %% "swagger-play2" % "1.5.0",  // This version adds Play 2.4 support.
// ScalaTest+ Play (have to use non-release 1.4.0-M4 version for now as it is only compatible with Play 2.4)
"org.scalatestplus" %% "play" % "1.4.0-M4" % "test",
"org.mockito" % "mockito-core" % "1.10.19" % "test"
)

我能得到什么见识?

scala playframework
1个回答
2
投票

您可以从这里开始:

import controllers.AssetsFinder
import org.specs2.mutable.Specification
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc._
import play.api.test._
import play.api.test.Helpers._

class EvTemplateTests
    extends Specification
    with DefaultAwaitTimeout
    with FutureAwaits
    with Results {

  val application: Application = GuiceApplicationBuilder().build()

  "render eval template" in new WithApplication(app = application) {
    implicit val assetsFinder = app.injector.instanceOf[AssetsFinder]
    val html = views.html.index("Hello")
    contentType(html) mustEqual "text/html"
    contentAsString(html) must contain("Hello")
  }

}

将此添加到LibraryDependencies中的jdbc之后:specs2 % Test

测试设置中最重要的部分是源自implicit AssetFinderGuiceApplicationBuilder

val application: Application = GuiceApplicationBuilder().build()
© www.soinside.com 2019 - 2024. All rights reserved.