2016-12-04 1 views
0

나는 외부 클라이언트 액세스 것처럼 내 서비스를 테스트하는 통합 테스트를 작성하려는 플레이 프레임 워크 2.5통합 테스트는 2.5

의 상단에 REST 서비스를 구축하고있다. - 문서 here를 사용

내 테스트 클래스 등이 오버라이드 (override) '응용 프로그램'에 OneServerPerSuite을 혼합 :

암시 적 재정 게으른 발 애플 리케이션 = 새로운 GuiceApplicationBuilder() 구축()

. 라우터 구성을 무시하고 싶지는 않다고 생각합니다.

import org.scalatest.FreeSpec 

import org.scalatestplus.play.OneServerPerSuite 
import play.api.inject.guice.GuiceApplicationBuilder 
import play.api.libs.ws.WSClient 

import scala.concurrent.Await 
import scala.concurrent.duration.Duration 


class ServerIntegration extends FreeSpec with OneServerPerSuite { 


    implicit override lazy val app = new GuiceApplicationBuilder().build() 


    "Server" - { 
    "When requested for a reply" - { 
     "should give it" in { 

     val ws = app.injector.instanceOf[WSClient] 

     val resonseFuture = ws.url(s"http://localhost:$port/my/defined/route").get() 

     val result = Await.result(resonseFuture, Duration.Inf) 

     println(result) 
     }}} } 

HTTP 서버를 시작한 것으로 보이지만 내 경로가 정의되어 있지 않은 것으로 보입니다. 나는 'Action Not Found'답장 (상태 404)을 얻고 있습니다.

서버를 정상적으로 실행할 때 ('sbt run') 브라우저에서 정의한 모든 작업에 액세스 할 수 있습니다.

답변

0

내 버그를 찾았습니다. 그것은 바보하지만 다른 사람에게 도움이 될 수 있습니다 내 conf의/루트 파일에서

, 나는에 @와 경로를 정의 그래서 같은 :

GET /       @com.company.service.controllers.serviceController.index 

이이 경로를 정적으로 발생하고 년후 이유를 먹으 렴 주입 (GuiceApplicationBuilder를 구축 할 때).

0

코드가 완전히 정확합니다.

프로젝트에 넣으면 그대로 작동합니다.

당신은 play-scala 템플릿을 생성하여 새 프로젝트를 그것을 확인하고 결과가 그래서

[info] Server 
[info] When requested for a reply 
AhcWSResponse(200, OK) 
[info] - should give it 
[info] application - ApplicationTimer demo: Stopping application at 2016-12-04T19:44:03.761Z after 0s. 

입니다

val resonseFuture = ws.url(s"http://localhost:$port/count").get()

처럼 count에 시험에 URL을 변경할 수 있습니다 - URL을 다시 확인