Running Unit Test on JSTestDriver
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.
The test server loads tests to the browser according to the
that define which test and corresponding production files should be loaded and in which order.
JSTestDriver server treats
*.conf files as test runner configuration files.
Create one or several configuration files in advance manually and then specify them in the run configuration.
On this page:
- Before you start
- Creating a test runner configuration file manually
- Starting a PyCharm default JSTestDriver test server
- Capture a browser to execute tests in
- Creating a JSTestDriver run configuration
- Launching unit tests
Before you start
- Make sure the JSTestDriver repository plugin is installed and enabled. The plugin is not bundled with PyCharm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
Creating a test runner configuration file manually
A test runner configuration file defines which test and corresponding production files should be loaded and in which order.
Any file with the extension
*.conf is treated as a test runner configuration file.
In the Project tree, select the parent folder of the
src(production) and the
testfolders, and choose New | File on the context menu.
In the New File dialog box, that opens, type a name of the configuration file with the extension
- Open the new file in the editor and specify the full path to the current folder and paths to the files to load relative to the current folder. Use wildcards to specify file name patterns. The required format is YAML, for more details, see description of test runner configuration files.
Starting a PyCharm default JSTestDriver test server
If you are going to use a test server running on another machine or listening to another port, start it according to the server-specific instructions and specify its URL address in the Server ares of the Run/Debug Configuration: JSTestDriver dialog box.
- Make sure the JSTestDriver plugin is enabled and at least one test runner configuration file is available in the project.
- Open the JSTestDriver Server tool window by doing one of the following:
- In the JSTestDriver Server tool window, that opens, click the Run a local server toolbar button .
Capture a browser to execute tests in
- Start the JSTestDriver Server if it is not running yet, and then switch to the JSTestDriver Server tool window.
To start a local browser with the Remote Console of the JSTestDriver, do one of the following:
- Click 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.
- 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.
Creating a JSTestDriver run configuration
- Open the Run/Debug Configuration dialog box by doing one of the following:
- Click the Add button on the toolbar and select the JSTestDriver configuration type.
- In the dialog box that opens, specify the test scope, configuration parameters, and activities to perform before test execution.
- Apply the changes and close the dialog box.
Launching unit tests
- To launch the tests according to a run configuration, select the JSTestDriver run/debug configuration from the list on the main toolbar. Then click the Run button to the right of the list.
- To launch a single test, open the test file in the editor and click the blue arrow icon in the gutter area next to the text to run.
- Monitor test execution in the Test Runner tab of the Run tool window as described in Monitoring and Managing Tests.