The most common way to run
Sbt recognizes Specification
abstract class can be executed by sbt. The test
command will run all the specifications in your project provided you put them in the src/test/scala
directory:
sbt> test
Most of the time however you will use the testOnly
command, either because you want to run one specification only or because you want to pass arguments:
sbt> testOnly org.acme.secret.KillerAppSpec
Only show failed tests:
sbt> testOnly org.acme.secret.KillerAppSpec -- xonly
Various sbt options can apply to test execution in sbt but here are the ones which you are most likely to use:
exclude some specifications: testOptions := Seq(Tests.Filter(s => Seq("Spec", "Unit").exists(s.endsWith)))
don’t execute the specifications in parallel parallelExecution in Test := false
pass testOptions in Test += Tests.Argument("exclude", "integration")
display results as soon as they’ve been executed logBuffered := false
When you run a specification, whatever environment you are in: sbt, shell, IDE,… you can specify different outputs for the results. For example, when you execute a specification with sbt, the results appear in the console. If you want JUnit XML files to be produced instead you need to pass the junitxml
argument. Adding any “output” argument will deactivate the console (you will see no output in the console) but you can enable it again by passing the console
argument. You can of course specify several outputs like html junitxml console
.
Here is a list of all the existing Printers
in
Argument | Section |
---|---|
console |
Console output |
junitxml |
JUnit XML output |
html |
Html output |
markdown |
Markdown output |
notifier |
Custom output |
printer |
Custom output |
With the testOnly
command arguments can be passed on the command line for selecting, executing or reporting a specification. Please consult the following sections for more information:
Notifier
interface (simple) or the Printer
interfaceall
argument