This article discusses the options for setting environment variables at test time in Java. It explains why the environment variable map is immutable in Java and provides workaround methods for modifying the environment variables map using reflection. It also explores various libraries that can be used to set environment variables at test time, such as JUnit Pioneer, System Stubs, System Rules, and System Lambda. The article concludes by discussing the risks and limitations of modifying environment variables at test time and suggests alternative approaches, such as dependency injection and using abstractions.
Table of contents
1. Overview2. The Challenge of Changing Environment Variables3. Setting Environment Variables With JUnit Pioneer4. Setting Environment Variables With System Stubs5. System Rules and System Lambda6. Avoid Mocking Environment Variables7. ConclusionSort: