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

This user guide will help you get rolling quickly with ScalaTest. First a brief orientation:

  • The central concept in ScalaTest is the suite, a collection of zero to many tests.
  • A test can be anything with a name that can start and either succeed, fail, be pending, or canceled.
  • The central unit of composition in ScalaTest is Suite, which represents a suite of tests.
  • Trait Suite declares run and other “lifecycle” methods that define a default way to write and run tests.
  • These lifecycle methods can be overridden to customize how tests are written and run.
  • ScalaTest offers style traits that extend Suite and override lifecycle methods to support different testing styles.
  • It provides mixin traits that override lifecycle methods of the style traits to address particular testing needs.
  • You define test classes by composing Suite style and mixin traits.
  • You define test suites by composing Suite instances.

To include ScalaTest in your sbt project, simply add this line:

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.6" % "test"

To include ScalaTest in your Maven project, use:

<dependency>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest_2.10</artifactId>
  <version>2.2.6</version>
  <scope>test</scope>
</dependency>

For other ways to include ScalaTest in your project, see Running your tests.

Using ScalaTest on your project is as easy as 1, 2, 3:

  1. Select your testing styles
  2. Define your base classes
  3. Start writing tests

ScalaTest is brought to you by Bill Venners and Artima.
ScalaTest is free, open-source software released under the Apache 2.0 license.

If your company loves ScalaTest, please consider sponsoring the project.

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

artima