How to set environment variables for test config?

In IDEA 14.1.4 running on CentOS 7, I have set an environment variable in a test run config:

IDEA_Test_RunConfig.png

But it seems the variable isn't being passed into the environment the test is running under. This is easily demonstrated with the following test:

package demo

import spock.lang.Specification

class ReadEnvVarSpec extends Specification {

    void "when I read environment variables those set in IDEA run configuration should be available"() {
        given:
            // test run configuration in IDEA has env var 'FOO' set to 'BAR' (without quotes)

            // Dump them all out for manual verification of issue
            
System.getenv().sort().each {k,v -> println "$k = $v"}
        when:
            String result = System.getenv('FOO')
        then:
            result == 'BAR'
    
}
}


This test fails and the environment variables I printed out do not include FOO.  If I run the same test from the command line after doing an export FOO=BAR, the test passes. So clearly, whatever environment IDEA is putting the FOO variable into isn't the environment seen by the test.

I'm sure there's something I didn't configure properly, but I'm not sure what it is.

Any help is appreciated.

--
jack

Please sign in to leave a comment.