IntelliJ IDEA 2016.2 Help

Working with Scala Tests

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

See Also

Last modified: 23 November 2016