[Java] When there is environment variable in Java test

less than 1 minute read

Thing you want to do

When I want to test including the place where the value is raised by the environment variable, I want to manage to die without the environment variable at the time of testing

solution

write in pom

pom.xml


                         <plugin>
                                 <artifactId>maven-surefire-plugin</artifactId>
                                 <version>{your version}</version>
+ <configuration>
+ <environmentVariables>
+ <TEST_ENV>100</TEST_ENV>
+ </environmentVariables>
+ </configuration>
                         </plugin>

This will give you 100 in the code where you say System.getenv("TEST_ENV")

Reference

https://maven.apache.org/components/surefire-archives/surefire-3.0.0-M1/maven-surefire-plugin/test-mojo.html#environmentVariables

Tags:

Updated: