2014-08-29 1 views
1

동일한 Play 응용 프로그램 내에서 실행되며 각 테스트마다 별도의 응용 프로그램이 아닌 여러 개의 테스트로 Specification을 실행하려고합니다. 이와 같이Specs2 순서대로 실행되지 않는 단계

I 인쇄해야합니다 다음과 같은 코드가 있습니다

Play app started 
[info] PlayRunningImmutableSpec 
[info]  
[info]  + 200 status expected 
[info]  
[info]  + 404 status expected 
Play app stopped 

하지만를 대신 인쇄 :

Play app started 
Play app stopped 
[info] PlayRunningImmutableSpec 
[info]  
[info] 
[info]  ! 200 status expected 
[error] ConnectException: : Connection refused: /127.0.0.1:19001 to http://127.0.0.1:19001/ 

나는 2.3.3과 Specs2 2.3 플레이 포함 형태 보증 활성제 1.2.10을 사용하고를 .12

다음 코드에 무엇이 잘못되었으며 대신 작동할까요?

import org.specs2.Specification 
import org.specs2.execute.Result 
import org.specs2.specification.Step 
import org.specs2.time.NoTimeConversions 
import play.api.Play 
import play.api.Play.current 
import play.api.http.{HeaderNames, HttpProtocol, Status} 
import play.api.libs.ws.WS 
import play.api.test._ 

class PlayRunningImmutableSpec extends Specification with NoTimeConversions with PlayRunners with HeaderNames with Status with HttpProtocol with DefaultAwaitTimeout with ResultExtractors with Writeables with RouteInvokers with FutureAwaits { 

    override def is = s2""" 
    ${Step(beforeAll)} 

    200 status expected  $e1 

    404 status expected  $e2 

    ${Step(afterAll)} 
    """ 

    def e1: Result = { 
    await(WS.url(s"http://127.0.0.1:${Helpers.testServerPort}").get()).status === 200 
    } 

    def e2: Result = { 
    await(WS.url(s"http://127.0.0.1:${Helpers.testServerPort}/missing").get()).status === 404 
    } 

    lazy val app = FakeApplication() 

    private def beforeAll = { 
    Play.start(app) 
    println("Play app started") 
    } 

    private def afterAll = { 
    Play.stop() 
    println("Play app stopped") 
    } 
} 

편집 :

내 오류가 사용 play.api.Play.start 방법 깨달았다 지금은 하나의 시작 및 종료 처리 할 수있는 간단한 특징이

: 제안에의

trait PlayServerRunning extends SpecificationLike { 

    override def map(fs: => Fragments): Fragments = Step(beforeAll)^fs^Step(afterAll) 

    private lazy val server = TestServer(Helpers.testServerPort) 

    private def beforeAll = { 
    server.start() 
    } 

    private def afterAll = { 
    server.stop() 
    } 

} 

답변

2

합니다. 테스트는 병렬로 실행됩니다 (실행 컨텍스트에 따른 구현 세부 정보 포함).

테스트가 순차적 일 필요가있는 경우이 방법으로 주석을 달아야합니다. 예컨대 : 중 변경 가능한 또는 불변의 사양이 작동하지 않습니다

"X" should { 
    sequential 

    "exp1" in { ... } 
    "exp2" in { ... } 
} 
+0

- 콘솔 출력이 변경되지 않습니다 (즉 : 연결이 거부) – Cory

+0

출력은 한 가지이지만, 실행 순서와 다를 수 있습니다. 순차적으로 어디에 넣었습니까? – cchantep

+0

좋은 지적이지만, 보간 된 "s2"문자열 내의 다양한 줄에서 "override def is"와 "$ {sequential}"전에 줄에서 해 보았습니다. 위의 코드 스 니펫을 사용하여이를 증명할 수 있습니다. – Cory

관련 문제