Search code examples
scalatestinghandlescalatestabort

Scalatest aborted tests handling


Is there any way how to handle an aborted test in ScalaTest? I'm using withFixture method, but I didn't find "Aborted" type:

override def withFixture(test: NoArgTest) = {
  super.withFixture(test) match {
    case failed: Failed => {
      insertScreen
      failed
    }
    case canceled: Canceled => {
      insertScreen
      canceled
    }
    //case aborted: **** => {something}
    case other => other
  }
}

Solution

  • In ScalaTest, Suites can complete or abort, tests can have one of four outcomes: succeeded, failed, canceled, or pending. An aborted suite means that some exception is thrown outside the context of a running test, such as in before/after code or the constructor invocation. None of those places would ever send an exception or result status through withFixture, because withFixure always executes during the execution of some test.