|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.junit.contrib.java.lang.system.EnvironmentVariables
public class EnvironmentVariables
The EnvironmentVariables
rule allows you to set environment variables
for your test. All changes to environment variables are reverted after the
test.
public class EnvironmentVariablesTest { @Rule public final EnvironmentVariables environmentVariables = new EnvironmentVariables(); @Test public void test() { environmentVariables.set("name", "value"); assertEquals("value", System.getenv("name")); } }
Common variables can be set directly after creating the rule
public class EnvironmentVariablesTest { @Rule public final EnvironmentVariables environmentVariables = new EnvironmentVariables() .set("name", "value"); @Test public void test() { assertEquals("value", System.getenv("name")); } }
You can ensure that some environment variables are not set by calling
clear(String...)
.
Warning: This rule uses reflection for modifying internals of the
environment variables map. It fails if your SecurityManager
forbids
such modifications.
Constructor Summary | |
---|---|
EnvironmentVariables()
|
Method Summary | |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
|
EnvironmentVariables |
clear(String... names)
Delete multiple environment variables. |
EnvironmentVariables |
set(String name,
String value)
Set the value of an environment variable. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EnvironmentVariables()
Method Detail |
---|
public EnvironmentVariables set(String name, String value)
name
- the environment variable's name.value
- the environment variable's new value. May be null
.
public EnvironmentVariables clear(String... names)
names
- the environment variables' names.
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |