Runners

The most common way to run specs2 specifications is to use sbt. In this section we will present the most important options for running specifications

Via sbt

Sbt recognizes specs2 as a “test framework”. This means that any class or object extending the 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 test-only command, either because you want to run one specification only or because you want to pass arguments:

sbt> test-only org.acme.secret.KillerAppSpec

Only show failed tests:

sbt> test-only org.acme.secret.KillerAppSpec -- xonly

sbt options

Various sbt options can apply to test execution in sbt but here are the ones which you are most likely to use:

Output

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 specs2 with links to the corresponding section in the User Guide for more information.

Argument Section
console Console output
junitxml JUnit XML output
html Html output
markdown Markdown output
notifier Custom output
printer Custom output

Arguments

With the test-only command arguments can be passed on the command line for selecting, executing or reporting a specification. Please consult the following sections for more information:

Now learn how to…

And if you want to know more