2016-10-27 37 views
0

我試圖在將它放到生產服務器上後測試我的play 2.5應用程序。基本上我只想運行與生產服務器設置一起在我的ApplicationSpec.scala中編寫的相同測試。我跟着文檔,但無法創建應用程序實例:如何編寫生產服務器測試與OneServerPerSuite一起玩

import play.api.test.Helpers.{GET => GET_REQUEST, _} 
import play.api.test._ 

class ProductionSpec extends PlaySpec with OneServerPerSuite { 

    implicit override lazy val app = 
    new GuiceApplicationBuilder().disable[EhCacheModule].router(Router.from { 
     case GET(p"/") => Action { play.api.mvc.Results.Ok("ok") } 
    }).build() 
    "AuthController" should { 

     "initialize tables" in { 
     val init = route(app, FakeRequest(GET, "/init")).get 
     status(init) mustBe OK 
     } 
    } 
} 

誤差

ProductionSpec.scala:25: not found: value GET 
... 
ProductionSpec.scala:25: value p is not a member of StringContext 

如何測試應用程序的生產環境中運行?

回答

0

的問題是,混合GETs,你也正在測試中的一條路徑,並請求其他

首先,你有兩個GETs(一個在每個庫)

play.api.test.Helpers._

play.api.routing.sird._

第二次初始化此路線GET(p"/")但您要求這一個route(app, FakeRequest(GET, "/init")).get

我固定的代碼和它的作品

import org.scalatestplus.play._ 
import play.api.test._ 
import play.api.test.Helpers._ 

import play.api.mvc._ 
import play.api.inject.guice.GuiceApplicationBuilder 
import play.api.routing._ 
import play.api.routing.sird._ 
import play.api.cache.EhCacheModule 
import play.api.libs.ws.WSClient 

class ProductionSpec extends PlaySpec with OneServerPerSuite { 

    implicit override lazy val app = 
    new GuiceApplicationBuilder().disable[EhCacheModule].router(Router.from { 
     case play.api.routing.sird.GET(p"/init") => Action { play.api.mvc.Results.Ok("ok") } 
    }).build() 
    "AuthController" should { 

     "initialize tables" in { 
     val init = route(app, FakeRequest(play.api.test.Helpers.GET, "/init")).get 
     status(init) mustBe OK 
     } 
    } 
} 

你應該知道何時使用每個GET

我希望這有助於

相關問題