stefanbirkner / system-rules

A collection of JUnit rules for testing code which uses java.lang.System.
http://stefanbirkner.github.io/system-rules
Other
546 stars 71 forks source link

Allow .set when instantiating EnvironmentVariables #49

Closed reftel closed 6 years ago

reftel commented 7 years ago

If some of the environment variable values to set are known statically, then let the user set these immediately when instantiating the rule, reducing the need for setup methods.

stefanbirkner commented 7 years ago

The environment variables that are set immediately when instantiating the rule are not reset at the end of the test.

To be honest it is already possible to set variables that are not reset. E.g. by not adding the @Rule annotation to the EnvironmentVariables rule.

reftel commented 7 years ago

You are correct, the variables set when instantiating the rule don't get reset. I'll try fixing that.

reftel commented 7 years ago

Updated to use an actual builder, leaving set as it was. Amended the testcase to show that variables now are reset after the execution of the rule.

stefanbirkner commented 6 years ago

This is now possible with System Rules 1.18.0: 063b1c82864c11b9dd3e14846665f796f340b7d5