运行Java集成测试时未设置环境变量 [英] Environment variables not set when running Java integration tests
问题描述
在为基本GET服务运行Java集成测试时,我们的应用程序代码无法检索环境变量。但是当我们运行应用程序本身时,它可以毫无问题地检索变量。
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.
我们正在使用intellij作为我们的IDE开发Mac(el captiain)。我们已经在bash_profile中导出了变量(例如export ORACLE_URL =*************)。我们可以在设置和刷新后回显该变量。
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.
我们完全不知道为什么它们在gradlew bootrun期间工作,但在测试运行期间没有。 bash_profile是存储本地环境变量的正确位置吗?
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?
推荐答案
我们当前为junit测试创建环境变量的工作解决方案是运行命令launchctl setenv USERNAME mrSmith。我们已将此添加到.bash_profile中以在重新启动之间保持变量。
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.
然而,Chii的回答似乎是更明智的行动路径。我们还没有设法让这个解决方案在我们的Intellij实例中运行。
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.
这篇关于运行Java集成测试时未设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!