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.

How to run your program using SBT with command line arguments

There are two possible ways to pass command line arguments to your application when running it with SBT. The first one is to run it inside the SBT shell, and second, from your operating system terminal. They are slightly different, but let’s look at both of them.

SBT shell

In order to , you need first to execute sbt command from your project directory. Then just add parameters after run command.

OS shell

When you want to run it from your OS shell, you need to enclose run command with parameters in quotes, just like this:

That’s it! As you can see it’s pretty simple. And you have any questions, please, let me know in the comments below!