Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单元测试控制器,ScalaTest正在使用中!框架_Scala_Unit Testing_Playframework 2.2_Scalatest - Fatal编程技术网

单元测试控制器,ScalaTest正在使用中!框架

单元测试控制器,ScalaTest正在使用中!框架,scala,unit-testing,playframework-2.2,scalatest,Scala,Unit Testing,Playframework 2.2,Scalatest,我正在使用Play 2.2和ScalaTest。这是我第一次尝试在我的游戏应用程序中测试控制器。我是这样做的: class TestArtistController extends PlaySpec with OneAppPerSuite { "ArtistController" must { "returns artists" in new WithApplication { val eventuallyResult = controllers.ArtistCont

我正在使用Play 2.2和ScalaTest。这是我第一次尝试在我的游戏应用程序中测试控制器。我是这样做的:

class TestArtistController extends PlaySpec with OneAppPerSuite {

  "ArtistController" must {

    "returns artists" in new WithApplication {
      val eventuallyResult = controllers.ArtistController.findNearCity("lyon")(FakeRequest())
      whenReady(eventuallyResult, timeout(Span(2, Seconds))) { result =>
        println(result.body) //it is an Enumerator[Array[Byte]]
        result.header.status mustBe 200
      }
    }
  }
}
它允许我正确地测试返回结果,但我不知道如何测试结果的主体
result.body
返回一个
Enumerator[Array[bytes]]
,我完全不知道如何转换它来检索我发送的
Json


这样做的好方法是什么?

导入
play.api.test.Helpers.
并使用助手函数,如
contentAsJson(res)
status(res)
,其中
res
是您操作的结果(在某些情况下,对于异步操作,您可能需要使用
res.run