IntelliJ IDEA 2017.1 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.

/help/img/idea/2017.1/scala_test_dependency.png

  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.
    /help/img/idea/2017.1/scala_create_test.png
  4. If the target test doesn't exist, you are prompted to create it.
    /help/img/idea/2017.1/scala_create_new_test.png
  5. In the Create Test dialog specify the necessary information and click OK.
    /help/img/idea/2017.1/scala_create_test_dialog2.png

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'.
    /help/img/idea/2017.1/scalaTest_run.png
  3. The result is displayed in the Test Runner tab of the Run tool window.
    /help/img/idea/2017.1/scala_test_run_result.png

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

Check the following example:

/help/img/idea/2017.1/scalaTest_code_RunTestInScope.png

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.

/help/img/idea/2017.1/scalaTest_RunDebugConf_for_Test_in_Scope.png
You can run the test and view the output inside the Run tool window.
/help/img/idea/2017.1/scalaTes_console_RunTestInScope.png

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

/help/img/idea/2017.1/scalaTest_RunDebug_for_Scope.png
You can run the test for the whole scope and view the output inside the Run tool window.
/help/img/idea/2017.1/scalaTest_console_RunFeatureSpecTest.png

Viewing a Scala Test File Structure

  1. Click View | Tool Windows | Structure.
  2. View the result in the Structure Tool Window.
    /help/img/idea/2017.1/scalaTest_structure_view.png

See Also

Last modified: 18 July 2017