在游戏框架2.4中测试控制器操作与最新版本

时间:2016-11-08 06:42:54

标签: scala unit-testing playframework-2.0 scalatest

我正在尝试使用ScalaTest在Play Framework中测试我的控制器操作。 我已阅读播放文档并尝试运行给定的示例以开始

我的控制器Application.scala

class Application extends Controller { 

def index1() = Action{
   Ok("ok")
 }

测试类

import scala.concurrent.Future

import org.scalatestplus.play._

import play.api.mvc._
import play.api.test._
import play.api.test.Helpers._
import akka.stream.Materializer
import play.api.libs.json.Json

class ExampleController extends PlaySpec with Results {

"testing the index page" should {
    "the test should be valid" in {
      val controller = new controllers.Application()
      val result: Future[Result] = controller.index1().apply(FakeRequest())
      val bodyText: String = contentAsString(result)
      bodyText mustBe "ok"
    }
  }
}

我在运行测试时遇到异常

ExampleController:
[info] testing the index page
[info] Exception encountered when attempting to run a suite with class name: ExampleController *** ABORTED ***
[info]   java.lang.AbstractMethodError:
[info]   at play.api.mvc.Results$class.$init$(Results.scala:605)
[info]   at controllers.Application.<init>(Application.scala:51)
[info]   at ExampleController$$anonfun$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(ExampleController.scala:38)
[info]   at ExampleController$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(ExampleController.scala:37)
[info]   at ExampleController$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(ExampleController.scala:37)
[info]   at org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22)
[info]   at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
[info]   ...
[error] Uncaught exception when running ExampleController: java.lang.AbstractMethodError
[trace] Stack trace suppressed: run last arteciate/test:test for the full output.
[info] DeferredAbortedSuite:
[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info]   java.lang.NoSuchMethodError: play.api.libs.functional.syntax.package$.functionalCanBuildApplicative(Lplay/api/libs/functional/Applicative;)Lplay/api/libs/functional/FunctionalCanBuild;
[info]   at models.institution.Gallery$.<init>(Gallery.scala:18)
[info]   at models.institution.Gallery$.<clinit>(Gallery.scala)
[info]   at TestModels.validationtest.<init>(validationtest.scala:251)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

请指导我犯错的地方

0 个答案:

没有答案