java 如何让 Netbeans 在运行测试时使用特定的 JVM 参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13320398/
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
How to make Netbeans use specific JVM parameters when running tests?
提问by assylias
I'm using Netbeans with Maven and TestNG. When running tests with the maven surefire plugin, I can setup some configuration parameters, in particular the logging level used for my tests (trace):
我在 Maven 和 TestNG 中使用 Netbeans。使用 maven surefire 插件运行测试时,我可以设置一些配置参数,特别是用于我的测试(跟踪)的日志记录级别:
-Dorg.slf4j.simpleLogger.defaultLogLevel=trace
-Dorg.slf4j.simpleLogger.logFile=System.out
However, when running a specific test file (CTRL + F6) or test method ("run focused test method"), Netbeans does not use surefire (which is good) and therefore ignores those parameters.
但是,在运行特定的测试文件 (CTRL + F6) 或测试方法(“运行重点测试方法”)时,Netbeans 不使用 surefire(这很好),因此会忽略这些参数。
Is there a way to change the JVM parameters used by Netbeans when it runs tests that way?
当 Netbeans 以这种方式运行测试时,有没有办法更改它使用的 JVM 参数?
This is somewhat similar to this other postbut my question is specific to Netbeans.
这有点类似于另一篇文章,但我的问题是针对 Netbeans 的。
采纳答案by Zólyomi István
From the documentation of Netbeans 7.2 (see Netbeans 7.2 changes, section Maven) :
来自 Netbeans 7.2 的文档(请参阅Netbeans 7.2 更改,Maven 部分):
... Now Test File always runs Maven by default, just like Test Project ...
...现在测试文件总是默认运行Maven,就像测试项目一样......
What version of Netbeans are you using? Probably you should just upgrade to 7.2.
您使用的是哪个版本的 Netbeans?可能你应该升级到 7.2。
回答by Alexandre Lavoie
In the Project Properties, you can create profiles under Run. In theses profiles you can customize VM Options. You can add your parameters here, create a Test config and Run config.
在项目属性中,您可以在运行下创建配置文件。在这些配置文件中,您可以自定义 VM 选项。您可以在此处添加参数,创建测试配置和运行配置。
回答by Akber Choudhry
Set fork property in the surefire plugin configuration in Maven. This will start a new JVM. Now, the second part is how to read the JVM parameters that you want into the new JVM. Depending on what you want to do, you might need to be read them from the environment.
在 Maven 的 surefire 插件配置中设置 fork 属性。这将启动一个新的 JVM。现在,第二部分是如何将您想要的 JVM 参数读入新的 JVM。根据您想要做什么,您可能需要从环境中读取它们。
回答by Jaime Casero
In my case i went to project/properties, then "Actions" category. There you'll find "Test file" and "Debug test" actions. Select them and place whatever properties you need in "Set properties" box.
就我而言,我去了项目/属性,然后是“操作”类别。在那里你会找到“测试文件”和“调试测试”操作。选择它们并将您需要的任何属性放在“设置属性”框中。
Not sure if this is only applicable for Maven projects...
不确定这是否仅适用于 Maven 项目...