2014-09-23 4 views
4

저는 ScalaTest 2.1.4를 SBT 0.13.5와 함께 사용하고 있습니다. 한 번의 테스트가 실패하면 오랜 시간이 걸릴 수있는 장기 실행 테스트 스위트가 있습니다 (다중 JVM Akka 테스트). 이 중 하나라도 실패하면 전체 제품군을 중단하고 싶습니다. 그렇지 않으면 특히 CI 서버에서 완료하는 데 오랜 시간이 걸릴 수 있습니다.테스트가 실패한 경우 Suite를 중단하도록 ScalaTest를 구성하는 방법은 무엇입니까?

스위트의 테스트가 실패 할 경우 어떻게하면 스위트를 중단하도록 ScalaTest를 구성 할 수 있습니까?

답변

4

실패한 테스트와 동일한 spec/suite/test에서 테스트 만 취소해야하는 경우 scalatest에서 혼합하여 CancelAfterFailure를 사용할 수 있습니다. 여기에서 전체적으로 취소하려는 경우 예 :

import org.scalatest._ 


object CancelGloballyAfterFailure { 
    @volatile var cancelRemaining = false 
} 

trait CancelGloballyAfterFailure extends SuiteMixin { this: Suite => 
    import CancelGloballyAfterFailure._ 

    abstract override def withFixture(test: NoArgTest): Outcome = { 
    if (cancelRemaining) 
     Canceled("Canceled by CancelGloballyAfterFailure because a test failed previously") 
    else 
     super.withFixture(test) match { 
     case failed: Failed => 
      cancelRemaining = true 
      failed 
     case outcome => outcome 
     } 
    } 

    final def newInstance: Suite with OneInstancePerTest = throw new UnsupportedOperationException 
} 

class Suite1 extends FlatSpec with CancelGloballyAfterFailure { 

    "Suite1" should "fail in first test" in { 
    println("Suite1 First Test!") 
    assert(false) 
    } 

    it should "skip second test" in { 
    println("Suite1 Second Test!") 
    } 

} 

class Suite2 extends FlatSpec with CancelGloballyAfterFailure { 

    "Suite2" should "skip first test" in { 
    println("Suite2 First Test!") 
    } 

    it should "skip second test" in { 
    println("Suite2 Second Test!") 
    } 

} 
+0

아주 좋습니다. 이제 첫 번째 스위트에서 초기화 기능을 설정하면 (설정 기능이 작동하는지 테스트 할 수있을뿐만 아니라 데이터베이스도 설정) 항상 먼저 실행되도록 보장할까요? 즉, 실행중인 순서가 소스 파일의 순서와 동일합니까? – akauppi

0

감사합니다. 이 var의를 사용하지 않고 수행 할 수 있습니다 궁금

trait TestBase extends FunSuite { 
    import TestBase._ 

    override def withFixture(test: NoArgTest): Outcome = { 
    if (aborted) Canceled(s"Canceled because $explanation") 
    else super.withFixture(test) 
    } 

    def abort(text: String = "one of the tests failed"): Unit = { 
    aborted = true 
    explanation = text 
    } 
} 

object TestBase { 
    @volatile var aborted = false 
    @volatile var explanation = "nothing happened" 
} 

: 여기 내 개선입니다.