When we run tests in IntelliJ IDEA the code is compiled by IntelliJ IDEA and the JUnit test runner is used. We get a nice graphical overview of the tasks that are executed and their results. If we use Gradle as the build tool for our project we can tell IntelliJ IDEA to always use Gradle for running tests.
We must open the Preferences or Settings dialog window. There we can search for
Gradle and then look for Build, Execution, Deployment | Build Tools | Gradle | Runner:
We can select different values for the Run tests using option. The default value is Platform Test Runner. To use Gradle we select Gradle Test Runner. Finally we can choose for Let me choose per test. Let's select the option Gradle Test Runner and click on the OK button to close the dialog window.
Next we run our test code from the IDE:
The test is started using the Gradle tasks
test with the option
--tests with the name of our test class. In the Run window we can see how the test is executed and the graphical representation of the tests:
If we choose the option Let me choose per test then we must first select the runner if we run a test for the first time:
Our choice is remembered for next runs of the same test. We must delete the run configuration from Run | Edit configurations... if we want to choose the runner again.
Written with IntelliJ IDEA 15 and Gradle 2.12.