2

I'm trying to run tests on a buildserver that doesn't have the environment variable I need set.

The variable is used from within a spring context xml file to resolve the location of property files.

e.g. classpath:config/${EnvironmentType}/myfile.properties

I'm using the failsafe plugin and trying the various documented methods (even deprecated ones) for setting the variables. None of it makes a lick of difference, the variable is never resolved.

My config is below :

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <id>Integration tests against mocks</id>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                    <configuration>
                        <skipTests>${skip.integration.mock.tests}</skipTests>
                        <includes>
                            <include>**/*ITMock.java</include>
                        </includes>
                        <argLine>-DEnvironmentType="DevelopmentIntegration"</argLine>
                        <systemPropertyVariables>
                            <EnvironmentType>DevelopmentIntegration</EnvironmentType>
                        </systemPropertyVariables>
                        <environmentVariables>
                            <EnvironmentType>DevelopmentIntegration</EnvironmentType>
                        </environmentVariables>
                        <systemProperties>
                            <property>
                                <name>EnvironmentType</name>
                                <value>DevelopmentIntegration</value>
                            </property>
                        </systemProperties>
                        <forkMode>false</forkMode>
                    </configuration>
                </execution>
                <execution>
                    <id>Verify</id>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <skipTests>false</skipTests>
                    </configuration>
                </execution>
            </executions>
        </plugin>

How can I get this env var set for my tests without actually setting it on the machine?

Note : Running this with mvn verify -DEnvironmentType="DevelopmentIntegration" works. I want it to work with just mvn verify.

Cheers, Peter

Programming Guy
  • 7,259
  • 11
  • 50
  • 59
  • Have you tried to update the version to 2.12.2 cause this version is in accordance with the documentation? Furthermore have you checked the output via mvn -X ... – khmarbaise Aug 27 '12 at 07:09
  • PEBKAC... The config above is in a parent project, I failed to notice it was being overridden by one of the child projects. I stuck with 2.12 as my version. 2.12.2 breaks because it doesn't create the failsafe report directory. – Programming Guy Aug 27 '12 at 08:26
  • Thank you. I had to search a lot to get this done and your question answered my question. The documentation on the failsafe plugin is just so sparse and so many links on the internet just give a page not found. – SK176H Oct 21 '16 at 17:38

1 Answers1

1

The config shown has value false for <forkMode>, which doesn't appear to be a valid value for this parameter per the docs.

I believe that the environment and system variables specified in the plugin configuration do not apply to the currently running JVM; they apply if the plugin creates a new JVM for running the tests. My guess is that the false value in the forkMode parameter is causing the forking not to happen. Try leaving it at the default (once) and see if that works.

user944849
  • 14,524
  • 2
  • 61
  • 83
  • 1
    I'll give you an accept for responding. The fork mode is wrong, but that wasn't the problem. (It actually just blows up if that config gets used.) I was overriding the config in a child project so my settings were being ignored. – Programming Guy Aug 28 '12 at 01:36