JavScript unit tests are run in a browser against a test server which actually handles the testing process.

The test server does not necessarily have to be on your machine. PyCharm has a local test server that is launched right from the IDE. This server allows you to capture a browser to run tests in, loads the test targets to the captured browser, controls the testing process, and exchanges data between the browser and PyCharm, so you can view test results without leaving the IDE.

To get access to using the test server, download, install, and enable the JSTestDriver plugin from the JetBrains default repository. Then restart PyCharm for the changes to take effect.

The test server loads tests to the browser according to the configuration files that define which test and corresponding production files should be loaded and in which order. JSTestDriver server treats *jstd and JSTestDriver.conf files as test runner configuration files. Create one or several configuration files in advance manually and then specify them in the run configuration.

To run JavaScript unit tests, perform these general steps:

  1. Make sure the JSTestDriver plugin is enabled and at least one test runner configuration file is available in the project.
  2. Open the JSTestDriver Server tool window by doing one of the following:
    • On the main menu, choose View | Tool Windows | JSTestDriver Server.
    • Click the Run button run.png on the toolbar, and then click the Start a local server link in the pop-up window that opens.
  3. In the JSTestDriver Server tool window, that opens, click the Run a local server toolbar button run.png.

To stop the server when you are through with unit testing, click the Stop the local server toolbar button stop.gif.

  1. Start the JSTestDriver Server if it is not running yet, and then switch to the JSTestDriver Server tool window.
  2. To start a local browser with the Remote Console of the JSTestDriver, do one of the following:
    • Click the the icon that indicates the browser of your choice.
    • If the browser is already opened, copy the contents of the Capture a browser using the URL read-only field and paste the URL in the address bar.

    In either case, the icon that indicates the chosen browser becomes active.

    You can have several browsers captured. However if you are going to debug your unit tests, you will have to appoint a browser for debugging in the Debug tab of the Run/Debug Configuration: JSTestDriver dialog box.

  3. Switch to the JSTestDriver Server tool window and click the icon that indicates the browser you just opened. PyCharm displays a message informing you that it is ready for executing tests.
  1. Open the Run/Debug Configuration dialog box by doing one of the following:
    • On the main menu, choose Run | Edit Configurations.
    • Press RunConfiguration and choose Edit Configuration on the context menu.
    • 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.
  2. Click the Add button add on the toolbar and select the JSTestDriver configuration type.
  3. In the dialog box that opens, specify the test scope, configuration parameters, and activities to perform before test execution.
  4. Apply the changes and close the dialog box.

See Also

Procedures:

Reference:

Web Resources: