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

Jack picture Jack · Dec 10, 2012 · Viewed 7.6k times · Source

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?

Answer

Régis Jean-Gilles picture Régis Jean-Gilles · Dec 10, 2012

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?