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

Asynchronous testing

Using Selenium

Using Scala-js

Using Inside

Using OptionValues

Using EitherValues

Using PartialFunctionValues

Using PrivateMethodTester

Using WrapWith

Philosophy and design

Migrating to 3.0

ScalaTest support in the IntelliJ Scala plugin

The IntelliJ Scala plugin comes with good ScalaTest support, including:

  • Running ScalaTest suite by right-clicking on the source
  • Showing the run results in a format that mirrors the structure of the suite/specification
  • Hopping from results to source code

Scala plugin

First make sure that latest version Scala plugin is installed and enabled. Go to:

File -> Settings... -> Plugins
On a Macintosh, you would go to:
IntelliJ IDEA -> Preferences... -> Plugins
IntelliJ Scala plugin

If it is not shown in the list, click Install JetBrains plugin and search for scala. Right click on the Scala plugin and choose Download and Install:

IntelliJ Install Scala plugin

Close the Browse JetBrains Plugins window, click Apply on the Settings window, and restart to activate the new plugin.

Using ScalaTest

To use ScalaTest in your Scala project, you must make sure ScalaTest is included as a library in your module/project settings, both ScalaTest 1.x and the latest 2.0 version (recommended) are supported.

If you are using sbt, you can add ScalaTest as dependency in your sbt build file:

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

and use sbt-idea to generate IntelliJ project files, which you can then easily open with IntelliJ.

If you want to configure the library dependency of IntelliJ project/module settings manually, please consult Configuring Module Dependencies and Libraries instead.

Running ScalaTest

After your project built successfully, you can run any ScalaTest suite by right clicking on the source:

IntelliJ Run ScalaTest

The results shown will follow the structure of the specification:

IntelliJ Run ScalaTest

You can hop to the related source by double-clicking on the test (leaf) nodes, for scope nodes (e.g. the A Stack node), you'll need to press the F4 key.

Creating ScalaTest Run Configuration Manually

You can also create a ScalaTest run configuration manually by following:

Run -> Edit Configurations

Click on + at the upper left corner and choose ScalaTest to create a new ScalaTest run configuration:

IntelliJ Create ScalaTest Run Configuration

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-2017 Artima, Inc. All Rights Reserved.