Environment variables not set when running Java integration tests

本小妞迷上赌 提交于 2020-01-24 20:37:13

问题


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?


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/38527766/environment-variables-not-set-when-running-java-integration-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!