【发布时间】:2015-07-15 02:43:34
【问题描述】:
我想使用 FakeRequest + Specs2 执行 POST 操作。
到目前为止,我已经能够编写用于发出 get 请求的代码
class ItemsSpec extends PlaySpecification {
"Items controller" should {
"list items" in new WithApplication {
route(FakeRequest(controllers.routes.Items.list())) match {
case Some(response) => status(response) must equalTo (OK) contentAsJson(response) must equalTo (Json.arr())
case None => failure
}
}
}
}
我面临的一些困难是
在控制器上进行发布时使用反向查找,而不是对操作和路径进行硬编码。
将 json 正文作为请求的一部分发送
解析结果并检查返回对象的某些属性是否匹配。
我做了一些谷歌搜索并找到了这个
https://www.playframework.com/documentation/2.4.x/ScalaTestingWithSpecs2
在最后一个例子中,它似乎在做一个 POST。但是路径是硬编码的,我不明白什么是基本操作。
有没有一种简单的方法可以为需要 POST 的 Web 服务编写测试用例?
【问题讨论】:
标签: scala playframework specs2