Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top