ScalaTest User Guide

Getting started

Selecting testing styles

Defining base classes

Writing your first test

Using assertions

Tagging your tests

Running your tests

Sharing fixtures

Sharing tests

Using matchers

Testing with mock objects

Property-based testing

Using Selenium

Other goodies

Philosophy and design

Migrating to 2.0

Using ScalaTest with sbt

ScalaTest's Framework supports using ScalaTest from sbt. In sbt version 0.10 and higher, simply add a line like this to your project file:

libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0" % "test"

Your test sources files go into src/test/scala. You can run all of them from the sbt console with:

> test

If you want to run particular suites, use test-only and provide their fully qualified names in a space separated list:

> test-only org.acme.RedSuite org.acme.BlueSuite

Or you can specify a glob:

> test-only *RedSuite

You can configure the output shown when running with sbt in four ways: 1) turn off color, 2) show short stack traces, 3) full stack traces, and 4) show durations for everything. To do so you must pass a -o argument to ScalaTest, and after the -o, place any combination of:

  • D - show durations
  • S - show short stack traces
  • F - show full stack traces
  • W - without color

For example, "-oDF" would show full stack traces and durations (the amount of time spent in each test).

To pass arguments from sbt to ScalaTest you can either add test options globally, like this:

testOptions in Test += Tests.Argument("-oD")

Or if you are using more than one test framework, like this:

testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oD")

You can also pass arguments for individual runs by placing them after --, like this:

> test-only org.acme.RedSuite -- -oD

ScalaTest is brought to you by Bill Venners, with contributions from several other folks. It is sponsored by Artima, Inc.
ScalaTest is free, open-source software released under the Apache 2.0 license.

Copyright © 2009-2016 Artima, Inc. All Rights Reserved.