Running Tests
sbt Commands
Start with the sbt Cheat Sheet for the commands you need most.
Selecting tests
sbt "testOnly *MyTest" # one suite
sbt "my-project/testOnly *MyTest" # one suite of a module
sbt "testOnly com.example.*" # a package
sbt "testOnly * -- encode" # tests whose name contains "encode"
sbt "testOnly * -- enc*ID" # * stands for any text
sbt "testOnly * -- encode decode" # tests matching either pattern
sbt 'testOnly * -- "encode an ID"' # a name with spaces
sbt "testOnly * -- outer/inner" # nested tests
sbt "testOnly * -- */inner" # nested tests of any parent
sbt "testOnly * -- --tags integration" # by tag
sbt "testOnly * -- --exclude-tags slow"A pattern matches anywhere in a test name and is case-sensitive. Quote a pattern that contains spaces.
To select nested tests, join the names with /. Spaces around it are optional. The bodies of the enclosing tests run too, since they define the nested tests, and a top-level test that matches the first part runs even when it has no nested tests. A pattern without / selects top-level tests, and all tests inside them run.
A test has to match a pattern, -t:, and the tags when you combine them. -t: and tags look at top-level tests only. Suites without a match print No tests found. For tags, see Organizing Tests.
UniTest prints a warning for options it does not know. To pass options to another test framework in the same build, scope them with Tests.Argument(framework, ...).
Use testOnly with options on sbt 2
On sbt 2, test skips suites that passed before and have not changed, even when you pass it a different name pattern. testOnly always runs what it selects. Property and fuzz tests also try no new inputs while they are skipped; use testFull or testOnly to run them again.
Log levels
Every UniTest can log with debug(...), info(...), and so on. Messages below info are hidden by default:
sbt "testOnly *MyTest -- -l debug" # everything at debug or above
sbt "testOnly *MyTest -- -l trace"
sbt "testOnly *MyTest -- -l:com.example.*=debug" # only one packageCombining options
sbt "testOnly *MyTest -- encode -l debug"
sbt "testOnly * -- --tags slow -l:com.example.*=trace"Options
Option (after --) | Meaning |
|---|---|
<pattern> | Run tests whose name matches the pattern, where * stands for any text; repeat to add more tests |
-t:<text> | Run top-level tests whose name contains the text; * stands for any text |
-l <level> | Default log level: error, warn, info, debug, or trace |
-l:<pattern>=<level> | Log level of the classes that match a pattern; repeatable |
--tags <tag> | Run tests that have the tag; repeat to require all of them |
--exclude-tags <tag> | Leave out tests that have the tag; repeatable |
--log-capture, --no-log-capture | Write logs into sbt's output of each suite, or not (see Test Output) |
Scala.js tests in a real browser
To run Scala.js tests in a real browser (headless Chromium/Firefox/WebKit) with ES module support — for DOM, web, and Electron code — see the sbt-uni-playwright Plugin.
Test Output
Test results are displayed with status symbols:
| Symbol | Status | Description |
|---|---|---|
+ | Success | Test passed |
- | Failure | Assertion failed |
x | Error | Unexpected exception |
~ | Skipped | Test was skipped |
? | Pending | Test not implemented |
! | Cancelled | Setup failed |
A suite that skips or cancels itself in its constructor or beforeAll is not counted as failed.
In CI (when the CI environment variable is set), UniTest on the JVM writes log messages from the thread running a suite (its constructor, hooks, and test bodies) into sbt's output for that suite, so they appear right above the result of the test that logged them. sbt may hold a suite's output until the suite ends, so local runs keep logs going straight to the console, where they show up live. Logs from other threads, such as a server's worker pool or a Future on the global pool, always go to the console. Override the default with a test argument:
Test / testOptions += Tests.Argument("--log-capture") // or "--no-log-capture"