Eclipse - 将 VM 参数传递给项目中的每个测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6703466/
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 16:37:04  来源:igfitidea点击:

Eclipse - passing VM parameter to every test in the project

javaeclipse

提问by Jarek

I need to pass a VM parameter to every test that is run in the project. Setting this manually doesn't seem to be the most convenient solution, so is there any possibility to pass the parameter to every test automatically.

我需要向项目中运行的每个测试传递一个 VM 参数。手动设置这似乎不是最方便的解决方案,因此是否有可能将参数自动传递给每个测试。

Thank you for help.

谢谢你的帮助。

回答by Daniel

We change the JRE Configuration in Eclipse (Preferences>Java>Installed JREs). There you can set default VM Arguments which are used for anything you run with that JRE.

我们在 Eclipse 中更改 JRE 配置(首选项>Java>已安装的 JRE)。您可以在那里设置默认 VM 参数,这些参数用于使用该 JRE 运行的任何内容。

Now simply configure your project to use this JRE (Java Build Path) and you should be on the right way.

现在只需将您的项目配置为使用此 JRE(Java 构建路径),您就应该走在正确的道路上。

Edit JRE - Eclipse

编辑 JRE - Eclipse

回答by Kit Ho

Eclipse have already a built-in JUnit for you.

Eclipse 已经为您提供了一个内置的 JUnit。

You can use JUnit to run different parameters on your main program.

您可以使用 JUnit 在主程序上运行不同的参数。

回答by djna

Run your test once, this creates a run configuration.

运行一次测试,这会创建一个运行配置。

Run-> Run Configurations -> JUnit, select your run configuration, then you have an arguments tab to specify JVM or program arguments.

Run-> Run Configurations -> JUnit,选择您的运行配置,然后您有一个参数选项卡来指定 JVM 或程序参数。

You can then duplicate this run configuration to use for other tests. I'm not aware of any way to make a default setting to be applied to all future test launches.

然后,您可以复制此运行配置以用于其他测试。我不知道有什么方法可以将默认设置应用于所有未来的测试启动。

回答by zawhtut

I think you are using "Program Argument" instead of "VM argument" now. If you use VM argument it's mean globally applied to all of your tests.

我认为您现在使用的是“程序参数”而不是“VM 参数”。如果您使用 VM 参数,则意味着全局应用于您的所有测试。