如何为 Eclipse 中的所有测试设置环境变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9832350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:52:14  来源:igfitidea点击:

How to set up environment variable for all tests in Eclipse?

eclipsejunit

提问by James Raitsev

Setting up environment variables for hundreds of tests get old very quick. Is there a way to declare an environmental variable globally in Eclipse?

为数百个测试设置环境变量很快就会过时。有没有办法在 Eclipse 中全局声明环境变量?

Can this be done in Eclipse? Can this be done outside of Eclipse?

这可以在 Eclipse 中完成吗?这可以在 Eclipse 之外完成吗?

enter image description here

在此处输入图片说明

采纳答案by James Raitsev

It seems that the only way to do it is to enable "Run all tests in the selected project .." and set Environmentvariables once there.

似乎唯一的方法是启用“ Run all tests in the selected project ..”并Environment在那里设置变量。

If you want to run a single test, and that test requires an environment variable set, it looks like you need to set that environment variable as part of that tests's settings.

如果您想运行单个测试,并且该测试需要一个环境变量集,那么您似乎需要将该环境变量设置为该测试设置的一部分。

enter image description here

在此处输入图片说明

回答by user1917821

In windows use the "start" command to spawn eclipse from command line with defined variables (linux has similar functionality)

在 Windows 中,使用“start”命令从带有定义变量的命令行生成 eclipse(linux 具有类似的功能)

Make file starteclipse.cmd

制作文件 starteclipse.cmd

================================

================================

SET VAR1=SOMEVALUE
SET VAR2=SOMEVALUE
start d:\eclipse\eclipse.exe

================================

================================

From command line go to the dir with starteclipse.cmd file and run it.

从命令行转到带有 starteclipse.cmd 文件的目录并运行它。

This will spawn eclipse with proper environment settings.

这将生成具有适当环境设置的 eclipse。

回答by inger

I also find it frustrating having to set env vars one by one. If you own the code and have a chance to change it, you'd be better off using a System property instead, which can be passed as VMArgs -Dprop=val.

我还发现不得不一个一个设置环境变量令人沮丧。如果您拥有代码并有机会对其进行更改,则最好改用 System 属性,该属性可以作为 VMArgs -Dprop=val 传递。

You can set VM args in a global level - Preferences | Java | Installed JREs, and Plugin Development | Target platform.

您可以在全局级别设置 VM 参数 - Preferences | 爪哇| 已安装的 JRE 和插件开发 | 目标平台。

Even if you can't change the code, most well civilised java libs support properties as well if not more than env vars- so it's worth double checking. (of course it's not an option for external processes).

即使您不能更改代码,大多数文明的 java libs 也支持属性,如果不超过 env vars-因此值得仔细检查。(当然,它不是外部进程的选项)。