When there are environment variables in Java tests

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>

Now you can get 100 where you say System.getenv ("TEST_ENV ") in your code.

reference

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

Recommended Posts

When there are environment variables in Java tests
What I learned in Java (Part 2) What are variables?
Replacing system environment variables by reflection in java
[Environment variables] What are rails environment variables?
JavaFX environment construction in Java 13
Resolve CreateProcess error = 206 when running Java in a Windows environment
If variables are no longer highlighted in Eclipse's Java editor
Why are class variables needed? [Java]
Java Spring environment in vs Code
<java> When "EXCEPTION_ACCESS_VIOLATION" appears in awt
Java array variables are reference types
How to name variables in Java
Setting project environment variables in intelliJ
Java local variables are thread safe
Java container performance degradation in Menicoa environment
When seeking multiple in a Java array
Behavior when Java annotation names are worn
[Docker] Use environment variables in Nginx conf
Handle system environment variables in Spring application.properties
Play Framework 2.6 (Java) environment construction in Eclipse
How to use environment variables in RubyOnRails
Do not declare variables in List in Java
Java application development environment created in VM environment
(Basic authentication) environment variables in rails and Docker
Solution for NetBeans 8.2 not working in Java 9 environment
There seems to be no else-if in java
A note when you want Tuple in Java
Points stuck in building VSCode & Java development environment
[Beginner] Install java development tool in cloud9 development environment.
[Java] output, variables
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
Java environment construction
Java development environment
[WIP] Java variables
Pi in Java
FizzBuzz in Java
[Java] Let's declare variables used in the loop in the loop [Variables in the block]
How to create a Java environment in just 3 seconds
Points stuck when running vite + Nginx in Docker environment
[Java] Sorting tips when strings and numbers are mixed
Data acquisition method memo when there is HashMap in HashMap
Maven fails in Java7 environment (Received fatal alert: protocol_version)
[Java] Difference between static final and final in member variables
Regarding overcapacity when setting Rails tutorial environment in Cloud 9
[Java] Get the file in the jar regardless of the environment
Ruby Hash stack overflows when there are many arguments
What I learned when building a server in Java
When you want to dynamically replace Annotation in Java8
In 2021, there is no topic in Java these days (Poem)
Differences in code when using the length system in Java
[Java Silver] What are class variables instance variables and local variables?
[Head panic] Priority when variables / methods with the same name are used in inherited classes
Apparently the environment variables are different when running sidekiq as a service on the production server