我正在试图弄清楚如何使用specs2在Play框架中测试多个URL,而我似乎无法在不启动多个服务器的情况下找到正确的方法。
import org.specs2.mutable._
import play.api.test._
import play.api.test.Helpers._
import play.api.libs.ws.WS
class testServer extends Specification {
running(TestServer(9000)) {
"Server starts" in {
await(WS.url("http://localhost:9000").get).status must equalTo(OK)
}
"Who" in {
await(WS.url("http://localhost:9000/url1").get).status must equalTo(OK)
}
"How" in {
await(WS.url("http://localhost:9000/url2").get).status must equalTo(OK)
}
"Why" in {
await(WS.url("http://localhost:9000/url3").get).status must equalTo(OK)
}
"Test4" in {
await(WS.url("http://localhost:9000/url4").get).status must equalTo(OK)
}
"Test" in {
await(WS.url("http://localhost:9000/url5").get).status must equalTo(OK)
}
"Help" in {
await(WS.url("http://localhost:9000/url6").get).status must equalTo(OK)
}
"Bogus" in {
await(WS.url("http://localhost:9000/url7").get).status must equalTo(OK)
}
}
}
答案 0 :(得分:2)
查看this question的答案。您需要为每个示例创建一个新的上下文。例如,你可以写:
import org.specs2._
import execute._
import specification.AroundExample
class testServer extends Specification with AroundExample {
def around[R <% Result](r: =>R) =
running(TestServer(9000))(r)
"Server starts" in {
await(WS.url("http://localhost:9000").get).status must equalTo(OK)
}
...
}