How to force IntelliJ IDEA to run Grails tests in the Test Environment

I recently stumbled across the next issue.  I was running a Grails 3 integration test in IntelliJ IDEA 15.0.3:

Grails 3 Test running in Development mode

My test was running in the development environment instead of in the test environment!

Why is this happening? Alvaro Sanchez Mariscal pointed me to the issue in the Grails Slack Channel.

The problem with running tests from IDEA is that IDEA does not use any Gradle task whatsoever

Solution: Tell IntelliJ to explicitly use the Grails test environment.

It is pretty easy configuration as shown below:

IntelliJ IDEA configuration to force tests to run in the test environment

Please note that I added -Dgrails.env=test to my default configuration for JUnit tests.  Add it to your default configuration, instead of in a single test configuration. If you do that, the next time you ask IntelliJ to run a test, it will create a new JUnit configuration based on your default configuration. That it is to say: your tests will run in the Grails test environment.

I solved this issue thanks to a Jeff Scott Brown tip in the Grails Slack Channel.  If you have not joined the channel, check it out.

Do you like to read about Groovy/Grails development? Yes, then Subscribe to Groovy Calamari a weekly curated email newsletter about the Groovy ecosystem which I happen to write 😉

Leave a Reply

Your email address will not be published. Required fields are marked *