@Retention(value=RUNTIME) @Target(value={METHOD,TYPE}) @Repeatable(value=ClearEnvironmentVariables.class) @ExtendWith(value=org.junitpioneer.jupiter.EnvironmentVariableExtension.class) public @interface ClearEnvironmentVariable
@ClearEnvironmentVariable
is a JUnit Jupiter extension to clear the value
of a environment variable for a test execution.
The key of the environment variable to be cleared must be specified via
key()
. After the annotated element has been executed, After the
annotated method has been executed, the initial default value is restored.
ClearEnvironmentVariable
is repeatable and can be used on the method and
on the class level. If a class is annotated, the configured variable will be
cleared for all tests inside that class.
WARNING: Java considers environment variables to be immutable, so this extension
uses reflection to change them. This requires that the SecurityManager
allows modifications and can potentially break on different operating systems and
Java versions. Be aware that this is a fragile solution and consider finding a
better one for your specific situation. If you're running on Java 9 or later, you
may have to add --add-opens=java.base/java.util=ALL-UNNAMED
to your test
execution to prevent warnings or even errors.
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
key
The key of the environment variable to be cleared.
|