Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Gradle Goodness: Configure Intellij Idea to Use Gradle as Testrunner

DZone's Guide to

Gradle Goodness: Configure Intellij Idea to Use Gradle as Testrunner

An awesome tutorial on making IntelliJ use Gradle to run your project tests.

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

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 cleanTest and 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.

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
gradle ,intellij ,java

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}