When running our Java integration tests for a basic GET service, our application code cannot retrieve environment variables. However when we run the application itself it can retrieve the variables without issue.
We are developing on a Mac (el captiain) with intellij as our IDE. We have exported the variables in our bash_profile (e.g. export ORACLE_URL="*************"). And we can echo the variable after setting and refreshing.
We are completely stumped as to why they work during a gradlew bootrun but not during a test run. Is the bash_profile the correct place to store local environment variables?
set the environmental variable via the run configuration for your test if you want to run it from intellij, rather than in your bash_profile (which runs when you start your terminal.
See the environmental variable section here (i assume you're using junit, but i think all run configurations have the environmental variables section)
Our current working solution to create environment variables for our junit tests is to run the command "launchctl setenv USERNAME mrSmith". We've added this to the .bash_profile to persist the variable between restarts.
However Chii's answer appears to be the more sensible path of action. We have not managed to get this solution working in our instance of Intellij.