![](/img/trans.png)
[英]How to test a controller method that uses a custom parser in play 2.5?
[英]How to write a test that uses subdomains in play?
我有一個使用子域的播放應用程序。
目前我在筆記本電腦上設置了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
trait中設置的,它只是從頭部派生的。
import play.api.http.HeaderNames
FakeRequest(GET, "/something").withHeaders(HeaderNames.HOST -> "sub.domain.com")
FakeRequest is just passed through the router of the
(if using the
路由helper), and what you get is the
來自控制器功能helper), and what you get is the
Result`。 這里沒有涉及無頭瀏覽器。
什么將使用模擬瀏覽器是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 ...
}
WithBrowser
對於測試是否已保存數據有點過分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.