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