how to test an Action[T] without a message body in play framework

两盒软妹~` 提交于 2019-12-14 03:09:48

问题


An Action[T] means that it accepts a request with body of type T.

Eg

def getQuestion:Action[JsValue] = silhouette.UserAwareAction.async(parse.json){...}

How do I test the above Action with a request which doesn't contain any body? In my unit test, I call the above action like the following

val request = FakeRequest("POST","ws/questions/get-question")
val responseFuture:Future[Result] = questionsTestEnv.questionsController.getQuestion(request)

But I get error

Error:(182, 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)

来源:https://stackoverflow.com/questions/55857052/how-to-test-an-actiont-without-a-message-body-in-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!