How to have SBT re-run only failed tests - scala

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.

If you are using the latest version of sbt simply run sbt testQuick.
http://www.scala-sbt.org/0.13/docs/Testing.html

Related

IntelliJ always runs entire ScalaTest suite 17 times

I am using the following versions.
IntelliJ 2020.2.3
SBT 1.3.7
Scala 2.11.12
Play Framework SBT plugin 2.7.3
We have a project with an app directory with sources and a test directory with 44 tests in various packages.
When I run sbt testOnly, it runs all 44 unit tests. When I make an IntelliJ run configuration with ScalaTest and Use sbt checked, it also runs all 44 unit tests.
When I also check Use UI with sbt in the test configuration, the tests still run but it executes the entire test suite 17 times in a row, sequentially. The following line appears in the output, which is followed by an entire test run with results, and then it runs again and again until it stops after 17 times. The UI shows results for all 748 tests run.
[IJ][my-app] $ {file:/home/me/Documents/my-app/}root/ testOnly
What is going wrong here?

what's the gradle equivalent of sbt's "testQuick"

Scala's sbt has the option to run only tests that previously failed. Is there a gradle equivalent?
https://www.scala-sbt.org/1.x/docs/Testing.html#testQuick
gradle does this automatically with all update-to-date tests marked as such, based on code changes since latest test passing.
You can also force re-run of tests if need be: How to run Gradle test when all tests are UP-TO-DATE?

SBT - why sbt giving compilation errors while running?

I am trying to merge two modules into single module. Both are successfully running modules. I merge two modules. And trying to run the test cases.
i am compiling source and testcases by using sbt commands:
sbt
clean
compile
project module-read
test:compile
it:test
Till test:compile everything working fine but after it:test, it showing lot of compilation issues.
Could I know best way of compiling?
The test:compile task will only compile tests within the src/test/scala folder as per the default sbt test configuration.
In order to compile your integration tests (in src/it/scala) you will have to run it:compile .
See http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Testing.html#integration-tests for more info.

Run scalatest in main instead of test through sbt?

Say I have a Scalatest file in the main directory, is there a sbt command to run the test such as testOnly or `runMain'? On IntelliJ, you are given the option to run the test.
You should be able to use test-only. From the scalatest user guide:
test-only org.acme.RedSuite org.acme.BlueSuite

How to run a single test in scalatest from maven

I have not found any documentation on how to do this. For JUnit the equivalent would be:
mvn -Dtest=org.apache.spark.streaming.InputStreamSuite test
tl;dr mvn test -Dsuites="some.package.SpecsClass"
I found an answer from here and it works:(https://groups.google.com/forum/#!topic/scalatest-users/Rr0gy61dg-0)
run test 'a pending test' in HelloSuite, and all tests in HelloWordSpec:
mvn test -Dsuites='org.example.
HelloSuite #a pending test, org.example.HelloWordSpec'
run all tests in HelloSuite containing 'hello':
mvn test -Dsuites='org.example.HelloSuite hello'
for more details: http://scalatest.org/user_guide/using_the_scalatest_maven_plugin
Found the answer: it is
-DwildcardSuites
So here is the example command line:
mvn -pl streaming -DwildcardSuites=org.apache.spark.streaming.InputStreamSuite test
Update Newer versions of scalatest use
-Dsuites
So the syntax would be:
mvn -pl streaming -Dsuites=org.apache.spark.streaming.InputStreamSuite test
Note that if you have some Java tests in the same module, as much of spark does, you need to turn them off -which you can do by telling surefire to run a test that isn't there
Here is the test that I've just been running
mvn test -Dtest=moo -DwildcardSuites=org.apache.spark.deploy.yarn.ClientSuite
That skips the java test and only runs the scala one.
One thing which scalatest doesn't seem to do is let you run a single test within a suite, the way maven surefire does. That's not ideal if you have one failing test in a big suite.
[Correction 2016-08-22: looks like you can ask for a specific suite by name; look at the other answers below. Happy to be wrong].