I need to use some environment variables in my unit tests. Consider the following test class
public class MyTest
{
private String myVar=null;
@Before
public void setUp()
{
myVar = System.getEnv("myEnv");
}
@After
public void tearDown() {}
@Test
public void myTestMethod()
{
assertNotNull(myVar);
}
}
now in the eclispe debug/run settings of the MyTest
class, i define the environment variable as
myEnv=myVal
and when I run the MyTest
class as a jUnit
test, the myTestMethod
passes.
However, when i try to run myTestMethod
as a jUnit
test, it gives me a NullPointerException
.
The only way to make it pass is to create a new run/debug configuration specifically for myTestMethod
and creating the environment variable again in the new configuration.
This is extremely frustrating as I can have dozens of environment variables and tests.
Is there any way to solve this problem in eclipse? I have not worked with intelliJ but does that also suffer from the same problem? Or is it more of a jUnit issue?