我有一个使用Play 2框架的简单Web应用程序。它有两个REST API:
我想为它实现功能测试。我希望测试多次调用/write
,然后验证/read
的结果。
但route
函数返回Future
,我找不到让 specs2 等待Future
的方法。
我的代码如下:
object MySpec extends Specification {
"/write * 2, then /read" in new WithApplication {
val write1 = route(app, FakeRequest(GET, '/write')).get
val write2 = route(app, FakeRequest(GET, '/write')).get
val read = route(app, FakeRequest(GET, '/read')).get
// how to chain the requests so the execute one after another, and the specs2 can wait for it?
status(read) must_==OK
}
}
答案 0 :(得分:1)
你不能做这样的事吗?
import play.api.mvc._
import play.api.test._
import scala.concurrent.Future
object MySpec extends Specification {
"/write * 2, then /read" in new WithApplication {
val result = for{
_ <- route(app, FakeRequest(GET, '/write'))
_ <- route(app, FakeRequest(GET, '/write'))
read <- route(app, FakeRequest(GET, '/read'))
}yield{ read }
status(result) mustEqual OK
}