Work with tests in Gradle
IntelliJ IDEA lets you use different test runners to execute tests in a Gradle project.
You can use JUnit to run your tests. In this case tests are run much faster due to the incremental compilation. You can delegate the testing process to Gradle. In this case when you run your tests, you will get the same results on the continuous integration (CI) server. Also, no matter how difficult your Gradle project is, tests that are run in command line will always work in IDE. You can also decide which test runner to use specifically per each test.
Configure and use a Gradle test runner
In the Gradle projects tool window, click .
In the Settings dialog, right-click Gradle and from the list, select Runner.
On the page that opens, in the Run test using list, select an option that you want to use for your test run. (The default value is Platform Test Runner.)
In your Gradle project, in the editor, create or select a test that you want to run.
From the context menu, select Run <test name>.
Alternatively, click the icon in the left gutter.
- Depending on what you chose as your test runner, IntelliJ IDEA runs your tests in one of the following ways:
If you selected Platform Test Runner, IntelliJ IDEA runs tests using a JUnit test runner and displays the output in the Run JUnit tool window.
- If you selected Gradle Test Runner, IntelliJ IDEA runs tests using a Gradle test runner and displays the output in the Run Gradle tool window.
While in the Run Gradle tool window, you can click the icon to get the Gradle test report.
You can also click the icon to check the previously saved tests' results.
You can also select Run 'name()' with coverage to see the code coverage for your test. It works for the platform test runner as well as for the Gradle test runner.
If you selected Let me choose per test, IntelliJ IDEA lets you choose between JUnit or Gradle to run your test. Once you have selected the test runner, IntelliJ IDEA will remember your selection and automatically will run your test using the option you've chosen.
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 Let me choose per test option is selected in the Runner settings, product% clears the Enable Gradle script debugging option located inside the Run/debug configuration and disables the breakpoints in 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 suits
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 icon and select Show internal Gradle test suits.
Rerun the tests to see the test results that include the Gradle internal ones.