2017-03-23 15 views
0

Play 2 프레임 워크를 사용하는 간단한 웹 앱이 있습니다.하나의 Play 2 specs2 단위 테스트에서 여러 요청을 수행하는 방법

  • /
  • 는/내가 그것에 대한 기능 테스트를 구현하려는

을 읽기, 쓰기 : 그것은 두 REST API를 가지고있다. 테스트에서 /write을 여러 번 호출 한 다음 /read의 결과를 확인합니다.

는 그러나 route 함수는 Future를 반환하고, 나는 specs2Future 기다릴 수 있도록하는 방법을 찾을 수 없습니다.

object MySpec extends Specification { 

    "/write * 2, then /read" in new WithApplication { 
    val write1 = route(app, FakeRequest(GET, '/write')).get 
    val write2 = route(app, FakeRequest(GET, '/write')).get 
    val read = route(app, FakeRequest(GET, '/read')).get 

    // how to chain the requests so the execute one after another, and the specs2 can wait for it? 

    status(read) must_==OK 
    } 
} 

답변

1

당신이 그런 짓을 할 수 없습니다 : 같은

내 코드가 보인다?

import play.api.mvc._ 
import play.api.test._ 
import scala.concurrent.Future 

object MySpec extends Specification { 

"/write * 2, then /read" in new WithApplication { 
    val result = for{ 
    _ <- route(app, FakeRequest(GET, '/write')) 
    _ <- route(app, FakeRequest(GET, '/write')) 
    read <- route(app, FakeRequest(GET, '/read')) 
    }yield{ read } 

    status(result) mustEqual OK 
}