ScalaTest in sbt: how to run specific tests

Imagine the situation, when you have several test suites for your application. And the problem arise, when you need to run only specific test or tests, to check the new fix, for example. There is absolutely no need to run all of them. To see, how you can do it with ScalaTest in sbt, let’s create a simple project ScalaTestDemo with three suites and some tests inside them.

  • TestSuiteA1
    • TestA1 – N1
    • TestA1 – N2
    • TestA1 – N11
  • TestSuiteA2
    • TestA2 – N1
  • TestSuiteB1
    • TestB1 – N1

Now your project should look like in the picture below.

If you want to run particular suites, you can use testOnly and provide their names in a space separated list

Or you can specify a mask.

But what if you want to run only specific test inside a particular suite? You can also pass arguments for individual runs by using testOnly and placing them after –. Parameter -t, for example, allows you to specify the name of the test.

Moreover, you can specify the names of the tests by substring and -z parameter.

That’s it. Simple and powerful. Now you are all set and able to run the tests you really want to.