ScalaTest in sbt: is there a way to run a single test without tags?

Related searches

I know that a single test can be ran by running, in sbt,

testOnly *class -- -n Tag

Is there a way of telling sbt/scalatest to run a single test without tags? For example:

testOnly *class -- -X 2

it would mean "run the second test in the class. Whatever it is". We have a bunch of tests and no one bothered to tag them, so is there a way to run a single test without it having a tag?

This is now supported (since ScalaTest 2.1.3) within interactive mode:

testOnly *MySuite -- -z foo

to run only the tests whose name includes the substring "foo".

For exact match rather than substring, use -t instead of -z.

Using ScalaTest with sbt, I know that a single test can be ran by running, in sbt, testOnly *class -- -n Tag Is there a way of telling sbt/scalatest to run a single test without tags? For example: � The general enhancement of running a single test "natively" via sbt syntax was one reason for the new test interface that went into 0.13.0. ScalaTest 2.0 will support this new interface (not sure about specs2, ScalaCheck, or junit), but the actual syntax and support in testOnly for running a single test was deferred to 0.13.1.

I wanted to add a concrete example to accompany the other answers

You need to specify the name of the class that you want to test, so if you have the following project (this is a Play project):

You can test just the Login tests by running the following command from the SBT console:

test:testOnly *LoginServiceSpec

If you are running the command from outside the SBT console, you would do the following:

sbt "test:testOnly *LoginServiceSpec"

TIL: run specific tests with `sbt testOnly` � Serge Gebhardt (, In sbt version 0.10 and higher, you add ScalaTest to your project in three easy steps. If you want to run particular suites, you can use test-only and provide their If tags to include is not specified, then all tests except those mentioned in the of a run (how long to wait for asynchronous operations) from the command line. I know that a single test can be ran by running, in sbt, test-only *class -- -n Tag Is there a way of telling sbt/scalatest to run a single test without tags? For example: test-only *class -- -X 2 it would mean "run the second test in the class. What

I don't see a way to run a single untagged test within a test class but I am providing my workflow since it seems to be useful for anyone who runs into this question.

From within a sbt session:

test:testOnly *YourTestClass

(The asterisk is a wildcard, you could specify the full path com.example.specs.YourTestClass.)

All tests within that test class will be executed. Presumably you're most concerned with failing tests, so correct any failing implementations and then run:


... which will only execute tests that failed. (Repeating the most recently executed test:testOnly command will be the same as test:testQuick in this case, but if you break up your test methods into appropriate test classes you can use a wildcard to make test:testQuick a more efficient way to re-run failing tests.)

Note that the nomenclature for test in ScalaTest is a test class, not a specific test method, so all untagged methods are executed.

If you have too many test methods in a test class break them up into separate classes or tag them appropriately. (This could be a signal that the class under test is in violation of single responsibility principle and could use a refactoring.)

ScalaTest 109: Mark your tests with tags to include or exclude them , Running a specific test suite or a single test is no doubt a useful and frequent requirement. Here's how to do that with sbt and ScalaTest. Both ScalaTest and Spock provide fluent BDD test. However I find that the best feature of Spock is that you can to create single scenario with multiple set of data and expected results. This is very much like Cucumber's Scenario Outline, only run at unit test level. I can't find other unit test framework/library that does that.

Just to simplify the example of Tyler.

test:-prefix is not needed.

So according to his example:

In the sbt-console:

testOnly *LoginServiceSpec

And in the terminal:

sbt "testOnly *LoginServiceSpec"

ScalaTest in sbt: how to run specific tests, Problem: You want a way to label your individual ScalaTest unit tests, When you run your tests, declare which tests you want to run, or not run. tag in the list of tests to be run, start SBT, and then issue the following test-only� ScalaTest in sbt: is there a way to run a single test without tags? Testing Battery Usage; Python package structure, for running unit tests; How can I know when to “refresh” my model object in Rails? How do I install jmeter on a Mac? SBT Test-Dependencies in Multiprojects: Make the Test-Code Available to Dependent Projects

Here's the Scalatest page on using the runner and the extended discussion on the -t and -z options.

This post shows what commands work for a test file that uses FunSpec.

Here's the test file:

package com.github.mrpowers.scalatest.example

import org.scalatest.FunSpec

class CardiBSpec extends FunSpec {

  describe("realName") {

    it("returns her birth name") {
      assert(CardiB.realName() === "Belcalis Almanzar")


  describe("iLike") {

    it("works with a single argument") {
      assert(CardiB.iLike("dollars") === "I like dollars")

    it("works with multiple arguments") {
      assert(CardiB.iLike("dollars", "diamonds") === "I like dollars, diamonds")

    it("throws an error if an integer argument is supplied") {

    it("does not compile with integer arguments") {
      assertDoesNotCompile("""CardiB.iLike(1, 2, 3)""")



This command runs the four tests in the iLike describe block (from the SBT command line):

testOnly *CardiBSpec -- -z iLike

You can also use quotation marks, so this will also work:

testOnly *CardiBSpec -- -z "iLike"

This will run a single test:

testOnly *CardiBSpec -- -z "works with multiple arguments"

This will run the two tests that start with "works with":

testOnly *CardiBSpec -- -z "works with"

I can't get the -t option to run any tests in the CardiBSpec file. This command doesn't run any tests:

testOnly *CardiBSpec -- -t "works with multiple arguments"

Looks like the -t option works when tests aren't nested in describe blocks. Let's take a look at another test file:

class CalculatorSpec extends FunSpec {
  it("adds two numbers") {
    assert(Calculator.addNumbers(3, 4) === 7)

-t can be used to run the single test:

testOnly *CalculatorSpec -- -t "adds two numbers"

-z can also be used to run the single test:

testOnly *CalculatorSpec -- -z "adds two numbers"

See this repo if you'd like to run these examples.

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� To rerun a test in the nested class, ScalaTest can create the nesting class via its public, no-arg constructor, and run it. The nesting class will create the actual class in which the test resides, and run it as a nested suite, thereby rerunning the test. Added a boolean excludeNestedSuites field to the primary constructor of class Filter. This

it's just test or run-main. Yes, it's fighting sbt: we need to mimick another build tool during a transitional phase and it does not copy resources to the class folder. In fact, I agree with our legacy tool: it is costly to copy (large) read-only resources. – fommil Aug 7 '14 at 8:41

90 ScalaTest in sbt: is there a way to run a single test without tags? 45 Detecting when ValueAnimator is done 30 How do I run PhantomJS on AWS Lambda with NodeJS

ScalaTest/ScalaUtils 2.0.M8 mostly contains Scaladoc documentation, but also contains some adjustments to Or in in ScalaUtils, the addition of a OneArgTest factory method, and one important bug fix. Here is the list of changes in 2.0.M8 compared to 2.0.M7:

  • Your subject says "Scalatest-sbt". When sbt is hyphenated people would normally think of a plugin. But, just to clarify, you're talking about using ScalaTest from a modern version of sbt like sbt 0.12, not joshcough/scalatest-sbt a plugin for sbt 0.5.2-p3 written 4 years ago. Correct?
  • Correct. This is an old question and I have since then figured out that no, it is not possible (as far as I know). I haven't closed it in case someone did in fact managed to figure out a way, but I no longer need this to be answered.
  • There is a thread on this (with participation from both Bill Venners and Mark Harrah) at!topic/scalatest-users/1oRMkudFAXM , but no solution yet
  • There's also a case for general support on running a single test sbt#911 (
  • Note that if you're running from the command line, you have to enclose everything after sbt in quotes, e.g. sbt "test-only *SingleTestSuite"
  • @SethTisue Would you be able to post a working example which uses -t for exact matching? I am unable to get it to work.
  • @rmin (if this helps you fix your problem, let me know how I should update my answer.)
  • Just to clarify, if you run it from the command line, it should be as single argument: sbt "testOnly *MySuite -- -z foo"
  • In case anyone wants to run a specific integration test (supposedly placed under src/it), they need to prepend it to testOnly. For instance, on the command line: sbt "it:testOnly *MyIntegrationTestSuite".
  • How can I filter on multiple substrings? Tests may be grouped in a hierarchy (WordSpec), and the name parts separated by when and should can repeat between tests. To chose one specific test I need to say "name contains this AND that".
  • Upvote because apparently the double quotes are necessary: sbt "test:testOnly *LoginServiceSpec"
  • Most useful answer for me here. 👍 But the commands can be slightly simplified; in SBT console: testOnly *LoginServiceSpec, and outside: sbt "testOnly *LoginServiceSpec"
  • for who are facing "No tests were executed": *YourTestClass must be class name. Not file name.
  • it was testOnly instead of test-only for me.