Testing in Gradle
In the Gradle project, you can create and run tests the same way you do in any other project.
IntelliJ IDEA also lets you change the default test runner for your testing process and even configure a test runner for each test.
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.
Click OK.
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.
note
Once you have selected the test runner, IntelliJ IDEA remembers your selection and automatically runs your test using the option you've chosen. If you want to make both options available once again, delete the created run configuration for the test.
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.
If you ran tests with the Gradle test runner, the additional Gradle options become available in the Run tool window. You can generate the Gradle test report
and run internal Gradle test suites.
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 Debug Gradle scripts 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 Debug Gradle scripts option.
For more information about debugging, refer to the Gradle debugging section.
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 testing 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.
Thanks for your feedback!