Run tests
Run the selected test or test folder: CtrlShiftF10
Stop the current test session: CtrlF2
There are several ways to run tests, including from a file or folder, using the Run widget, and from the Structure tool window. This article covers running tests in general. If you're looking for information for a specific build tool, see:
If your tests don't require any specific actions before start, and you don't want to configure additional options, such as code coverage, you can run them by using the following options:
Place the caret at the test class to run all tests in that class, or at the test method, and press CtrlShiftF10. Alternatively, click the gutter icon next to the test class or test method and select Run '<test name>' from the list.
The gutter icon changes depending on the state of your test:
The gutter icon marks a set of tests.
The gutter icon marks new tests.
The gutter icon marks successful tests.
The gutter icon marks failed tests.
To run all tests in a folder, select this folder in the Project tool window and press CtrlShiftF10 or select Run Tests in 'folder' from the context menu.
When you run a test, IntelliJ IDEA creates a temporary run configuration. You can save temporary run configurations, change their settings, share them with other members of your team. For more information, refer to Run/debug configurations.
Create a new run configuration or save a temporary one.
Use the Run widget on the main toolbar to select the configuration you want to run.
Click or press ShiftF10.
In the Structure tool window, you can select one or several test methods in a class to run. In this case, the IDE also creates a temporary run configuration with these methods that you can save and edit.
In the Structure tool window, right-click one or several test methods and select Run 'method name' (CtrlShiftF10).
The tool window allows you to add test methods to an existing run configuration (for JUnit and TestNG tests) in which the test scope is specified by means of a pattern. You can add methods from several different classes creating a test suite.
Right-click a method in the Structure tool window and select:
Add to temp suite: <Configuration_name> if there is only one configuration with the Pattern test scope.
Add to JUnit Pattern Suite (JUnit) / Add to Temp Suite (TestNG) if there are several configurations with the Pattern test scope. In this case, a popup appears in which you can select the target configuration.
tip
To preserve the tab of a run configuration even if you execute another run configuration, you may pin it.
After IntelliJ IDEA finishes running your tests, it shows the results in the Run tool window on the tab for that run configuration. For more information about analyzing test results, refer to Explore test results.
The console on the right shows the output of the current test session. The test results toolbar located above the list of test results provides you with several helpful options.
When you want to check that your changes wouldn't break the code before pushing them, you can do that by running tests as commit checks.
note
Press Alt00 to open the Commit tool window and click Show Commit Options .
Under the Commit Checks menu, next to the Run Tests option, click Choose configuration and select which configuration you want to run. This can be a test configuration provided by your build tool, for example,
gradle test
or a single test class from the project.
After you have set up the test configuration, the specified tests will run every time you make a commit.
Use the following options on the test results toolbar of the tab for the run configuration:
Click or press CtrlF2 to terminate the process immediately.
Click to terminate the process gracefully, allowing shutdown hooks to run.
Right-click a test on the tab for the run configuration in the Run tool window and select Run 'test name'.
Click on the test results toolbar or press CtrlF5 to rerun all tests in a session.
Click on the test results toolbar to rerun only failed tests.
Hold Shift and click to choose whether you want to Run the failed tests again or Debug them.
You can configure the IDE to trigger tests that were ignored or not started during the previous test run together with failed tests. Click on the test results toolbar and enable the Include Non-Started Tests into Rerun Failed option.
In IntelliJ IDEA, you can enable the autotest-like runner: any test in the current run configuration restarts automatically after you change the related source code.
Click Rerun Automatically on the test results toolbar to enable the autotest-like runner.
If you don't know why a test fails, you can debug it.
In the editor, click the gutter on the line where you want to set a breakpoint.
There are different types of breakpoints that you can use depending on where you want to suspend the program. For more information, refer to Breakpoints.
Right-click the gutter icon next to the failed test and select Debug 'test name'.
The test will rerun in debug mode. After that, the test will be suspended, allowing you to examine its current state.
You can step through the test to analyze its execution in detail.
Thanks for your feedback!