IntelliJ IDEA 2017.2 Help

Working with Scala Tests

The following is only valid when Scala Plugin is installed and enabled!

IntelliJ IDEA lets you create and run the following Scala tests:

IntelliJ IDEA supports the following methods in Scala tests:
  • string constants
  • constructions like immutable string variables
  • concatenation
  • substring
  • stripSuffix
  • stripPrefix
  • toLowerCase
  • replace
  • trim

In this section:

Creating a Scala Test

Before you start creating Scala tests, make sure you have the appropriate scala test dependency version added to your SBT project or you have the appropriate test library downloaded to your regular Scala project. You can use Project Structure dialog for these purposes.

scala test dependency

  1. Open the class of interest in the editor.
  2. Place the cursor within the line containing the class declaration.
  3. On the context menu, choose Go to | Test.
    scala create test
  4. If the target test doesn't exist, you are prompted to create it.
    scala create new test
  5. In the Create Test dialog specify the necessary information and click OK.
    scala create test dialog2

Running Scala Tests

  1. Open your test file.
  2. In the Editor enter your code, right-click on the class and from the context menu, select Run 'test name'.
    scalaTest run
  3. The result is displayed in the Test Runner tab of the Run tool window.
    scala test run result

You can also run the tests inside the scope for scalaTest.

Check the following example:

scalaTest code RunTestInScope

If you open context menu for one of the tests inside the scope, you can create a Run/Debug configuration just for the specified test inside that scope.

scalaTest RunDebugConf for Test in Scope
You can run the test and view the output inside the Run tool window.
scalaTes console RunTestInScope

If you open a context menu for the whole scope, you can create a Run/Debug configuration for all the tests inside the scope.

scalaTest RunDebug for Scope
You can run the test for the whole scope and view the output inside the Run tool window.
scalaTest console RunFeatureSpecTest

Viewing a Scala Test File Structure

  1. Click View | Tool Windows | Structure.
  2. View the result in the Structure Tool Window.
    scalaTest structure view
Last modified: 29 November 2017

See Also