Search code examples
scalaspecs2

How do you run only a single Spec2 specification with SBT?


If you have 2 tests defined in your SBT project:

class Spec1 extends Specification {
  def is =
    "Tests for specification 1" ^
      p ^
      "Test case 1" ! todo ^
      end
}

and

class Spec2 extends Specification {
  def is =
    "Tests for specification 2" ^
      p ^
      "Test case 2" ! todo ^
      end
}

Then running test from inside SBT will execute both these tests. What is the simplest way to run only one of these tests?


Solution

  • Use the test-only sbt command.

    sbt> test-only com.example.MySpec
    

    You can even use a wildcard to run a range of tests. See How to execute tests that match a regular expression only?