RubyMine 2016.2 Help

Running Mocha Unit Tests

On this page:

Before you start

  1. Make sure the Node.js runtime environment and the Mocha framework are installed on your computer.
  2. Make sure the NodeJS repository plugin is installed and enabled. The plugin is not bundled with RubyMine, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

See Preparing to Use Mocha Test Framework for details.

Creating a Mocha run configuration

  1. Open the Run/Debug Configuration dialog box by doing one of the following:
    • On the main menu, choose Run | Edit Configurations.
    • Open the test file in the editor, and then choose Create <file name> on the context menu.
    • Select the test file in the Project tool window, and then choose Create <file name> on the context menu of the selection.

    Click the Add button add on the toolbar and select the Mocha configuration type. The Run/Debug Configuration: Mocha dialog box opens.

  2. Specify the location of the Node.js executable file and the Mocha package.
  3. Specify the working directory of the application. All references in test scripts will be resolved relative to this folder, unless such references use full paths.

    By default, the field shows the project root folder. To change this predefined setting, choose the desired folder from the drop-down list, or type the path manually, or click the Browse button browseButton.png and select the location in the dialog box, that opens.

  4. Specify the tests to run:
    • All in directory: choose this option to run all the tests from files stored in a folder. In the Test directory field, specify the folder with the tests. To have RubyMine look for tests in the subfolders under the specified directory, select the Include subdirectories check box.
    • File pattern: choose this option to have RubyMine look for tests in all the files with the names that match a certain mask and specify the mask in the Test file pattern field.
    • Test file: choose this option to run only the tests from one file and specify the path to this file in the Test file field.
    • Suite: choose this option to run individual suites from a test file. In the Test file field, specify the file where the required suites are defined. Click the Suite name field and configure a list of suites to run. To add a suite to the list, click addRoot.png and type the name of the required suite. To remove a suite, select it in the list and click minusSign.png
    • Test: choose this option to run individual tests from a test file. In the Test file field, specify the file where the required tests are defined. Click the Test name field and configure a list of tests to run. To add a test to the list, click addRoot.png and type the name of the required test. To remove a test, select it in the list and click minusSign.png
  5. Choose the interface used in the test to run.
  6. Apply the changes and close the dialog box.

See Also

Last modified: 30 November 2016