title: unit testing with code that depends on environment variable
body: <p>We have small set of environment variables exposed to control our application behavior.  Application code is in java.  (Environment variables may be evil, but the have a purpose in this special case)</p>
  
  <p>What is the best way to unit test this? How can I create environment variables, set it to different values and call the tests repeatedly?</p>
  
  <p>Current solution is to use   env element in junit tasks . For example below</p>
  
  <pre><code> &lt;env key="BASE_PLUGINS_FOLDER" value="c:/temp"/&gt;
  </code></pre>
  
  <p>code sets environment variable for the test. (This works only when fork mode is set to true)</p>
  
  <p>This means I have to create multiple test sections in ant build file and corresponding test else where. This could become unmanageable pretty fast.</p>
  
  <p>I feel there could be a better way, that is fully a junit-java code. Not sure how.</p>