我的controller
的定义如下:
def getQuestion = silhouette.UserAwareAction.async(parse.json){//anyone (logged in or not) can see a question
implicit request => {...}
}
它需要一个json
主体。如果请求不包含任何正文,我想测试其行为。
以下是我编写的测试用例
"mycontroller" should {
"should return error if json body is missing in the request" in {
val testEnv = new TestEnv(components = components)
val request = FakeRequest("POST","ws/questions/get-question")
val responseFuture:Future[Result] = testEnv.myController.getQuestion(request)
val responseBody = contentAsJson(responseFuture)
println(s"received response ${responseBody}")
val result = (responseBody \ "result").get.as[String]
val additionalInfo = (responseBody \ "additional-info").get.as[String]
result mustBe "error"
}
}
但是我遇到了以下错误
Error:(181, 92) type mismatch;
found : play.api.test.FakeRequest[play.api.mvc.AnyContentAsEmpty.type]
required: play.api.mvc.Request[play.api.libs.json.JsValue]
val responseFuture:Future[Result] = questionsTestEnv.questionsController.getQuestion(request)
如何将没有任何消息正文的请求传递给控制器?