Hi Matt,
We've been using a trait in our Stairway to Scala course exercises that does that. It does it for just the suite you mix it into. Is that the kind of behavior you want, or do you want an entire run to abort after the first failure perhaps?
Here's the trait we are using:
import org.scalatest._
import events.Event
import events.TestSucceeded
import scala.collection.mutable.ListBuffer
trait StopOnFirstFailure extends SuiteMixin { this: Suite =>
override def runTests(testName : Option[String], args: Args): Status = {
import args._
val stopRequested = stopper
// If a testName is passed to run, just run that, else run the tests returned
// by testNames.
testName match {
case Some(tn) => runTest(tn, args)
case None =>
val statusList = new ListBuffer[Status]()
val tests = testNames.iterator
var failed = false
for (test <- tests) {
if (failed == false) {
val status = runTest(test, args)
statusList += status
failed = !status.succeeds()
}
}
new CompositeStatus(Set.empty ++ statusList)
}
}
}
This isn't in ScalaTest itself because no one ever asked for this behavior until today, so I wasn't sure whether it was generally needed. It is useful for training people, because the students can just focus on the next failed test. Not sure still how common this need is generally.
Bill