Testing in Gradle
IntelliJ IDEA also lets you change the default test runner for your testing process and even configure a test runner for each test.
Configure a test runner
In the Gradle tool window, click to open the Gradle settings page.
- In the Run test using list, select one of the following test runner options for the selected Gradle project:
Gradle: IntelliJ IDEA uses Gradle as a default test runner. As an outcome, you get the same test results on the continuous integration (CI) server. Also, tests that are run in the command line will always work in the IDE.
IntelliJ IDEA: select this option to delegate the testing process to IntelliJ IDEA. In this case, IntelliJ IDEA uses the JUnit test runner and tests are run much faster due to the incremental compilation.
Choose per test: select this option to configure which test runner (Gradle or IntelliJ IDEA) to use specifically per each test.
Run Gradle tests
In your Gradle project, in the editor, create or select a test to run.
- From the context menu, select Run <test name>.
Alternatively, click the icon in the left gutter.
If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.
If you want to see the code coverage when you run a test, select the Run 'name()' with coverage option. It works for both IntelliJ IDEA and the Gradle test runners.
- IntelliJ IDEA runs the tests with the configured test runner and displays the output in the test tab of the Run tool window.
Debug Gradle tests
In your Gradle project, in the editor, create or select a test that you want to debug.
From the context menu, select Debug <test name>.
If the Choose per test option is selected in the Gradle settings, IntelliJ IDEA clears the Enable Gradle script debugging option located inside the Run/debug configuration and disables the breakpoints in the Gradle scripts. This is done to speed up your debugging process. You can manually enable or disable breakpoints in the Gradle scripts by selecting or clearing the Enable Gradle script debugging option.
Run internal Gradle test suites
Sometimes, in the multi-module projects you might want to see information about Gradle internal tests suites. For example, when tests are run in parallel, you can make IntelliJ IDEA display information about the tests processes. IntelliJ IDEA also displays how many of those processes are working simultaneously.
In the Run tool window, click the select Show Internal Gradle Test Suites.
Rerun the tests to see the test results that include the Gradle internal ones.