Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Grails 3 app with 'gradle test' uses wrong environment config

Tags:

gradle

grails

I have a Grails 3 application that I'm trying to configure an embedded datastore for functional tests for. I have the configuration for the datastore specific to the 'test' environment.

When I run 'grails test-app', the app connects to the correct datastore and my functional tests pass.

When I try testing the application with 'gradle test', it tries to connect to the datastore for the development environment and fails.

I have tried specifying the Grails environment to use for the gradle test task by adding this to build.gradle:

test {
    String testEnvArg = '-Dgrails.env=test'

    if (jvmArgs) {
        jvmArgs.add(testEnvArg)
    } else {
        jvmArgs = [testEnvArg]
    }
}

But the behavior appears to be unchanged.

How can I make the gradle 'test' task use the correct Grails environment configuration?

like image 595
Joseph Downing Avatar asked Sep 28 '22 17:09

Joseph Downing


2 Answers

You must specify environment:

gradle -PgrailsEnv=test test
like image 99
kNo Avatar answered Oct 01 '22 01:10

kNo


To boot run with production environment and gradle wrapper below worked:

./gradlew -Dgrails.env=production bootRun

And with requested test environment:

./gradlew -Dgrails.env=test bootRun

like image 39
Mahesh Pujari Avatar answered Oct 01 '22 01:10

Mahesh Pujari