Bla*_*man 3 junit scala playframework
我有一个使用子域的播放应用程序.
目前我在笔记本电脑上设置了dns,因此我可以在本地浏览URL,如:
subdomain1.myappurl.com:9000/subdomain2.myappurl.com:9000/
(我的myappurl指向127.0.0.1).
我想创建一个使用这些URL的测试(我想提供URL)
我怎么能用FakeRequest做到这一点?
另外,什么是FakeRequest,它是一个无头浏览器?理想情况下,我想创建一个集成测试(但不测试UI方面的东西),以确保在登录/注销等时数据正确写入数据库.
编辑:根据OP的注释,有一种方法可以FakeRequest通过将其添加为标题来覆盖主机名.它似乎request.host实际上是在Request特征中设置的,它只是从标题中派生出来的.
import play.api.http.HeaderNames
FakeRequest(GET, "/something").withHeaders(HeaderNames.HOST -> "sub.domain.com")
Run Code Online (Sandbox Code Playgroud)
来自控制器功能的FakeRequest is just passed through the router of theFakeApplication (if using the路由helper), and what you get is theResult`.这里没有涉及无头浏览器.
什么将使用模拟浏览器是WithBrowser帮手.
"go to the right url" in new WithBrowser(webDriver = WebDriverFactory(HTMLUNIT)) {
browser.goTo("google.com")
browser.pageSource must not contain("Bing")
// Do other things ...
}
Run Code Online (Sandbox Code Playgroud)
WithBrowser 对于测试数据是否已保存来说有点过分.
| 归档时间: |
|
| 查看次数: |
357 次 |
| 最近记录: |