samedi 30 mai 2015

Unit testing controllers with ScalaTest in Play! framework

I'm working with Play 2.2 and ScalaTest. It's the first time I'm trying to test a controller in my play application. I do it this way:

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
      }
    }
  }
}

It allows me to correctly test the return result but I don't know how to test the body of the result. result.body returns an Enumerator[Array[bytes]] and I totally don't know how I could transform it to retrieve the Json that I'm sending.

What is the good way to do this?

Aucun commentaire:

Enregistrer un commentaire