15

Is there a way to have SBT re-run only the tests that have failed in the last run of the test suite? For example, if I run sbt test and 3 out of the 20 tests I run fail, is there any command I can run to have SBT just re-run those 3 tests that fail?

Specifically I am using Scala Test and Scala Check for the tests I am running through SBT.

Christopher Wells
  • 1,796
  • 1
  • 14
  • 20

1 Answers1

14

If you are using the latest version of sbt simply run sbt testQuick.

http://www.scala-sbt.org/0.13/docs/Testing.html

Cameron Meyer
  • 172
  • 1
  • 3
  • 3
    Running `sbt testQuick` does not work, as it re-runs all of the tests in a set of Scala Test tests when at least one of them fails. Additionally it ignores all ScalaCheck test whether they failed or not. – Christopher Wells Mar 04 '17 at 19:41
  • 4
    I don't believer there is a way to rerun all failed tests inside a suite without it running the whole test suite. Also, you will need to perform the ScalaCheck tests inside a ScalaTest to get those to rerun along with the ScalaTests. Here is a decent example of how to do that. http://sanj.ink/posts/2016-07-06-how-to-run-scalacheck-from-scalatest-and-generate-html-reports.html – Cameron Meyer Mar 04 '17 at 20:46
  • I'm using sbt version 1.3.3 and sbt testQuick did not work for me. What worked was to go to the sbt shell and run `testOnly` with the name of the test classes which were failed. Example : `testOnly clients.MyClientSpec` – caytekin Dec 09 '19 at 15:08