I want to setup default IGNITE_HOME = /home/arjun/Desktop/apache-ignite-2.7.0-bin environmental variable to my whole project test classes instead of setting every time for new classes.
How can i setup?
Got to Run -> Edit Configurations -> Defaults, choose a default you use during testing (e.g. Application for regular Java programs or JUnit for JUnit tests) and change the environment variables there. From now on the new configurations you add (e.g. when start a new test) will have these settings.
Note that the old configurations (e.g. the programs you've already run) won't be affected. You need to delete the existing configurations so that they're recreated with new defaults. Choose each configuration that is not in Defaults and hit del or the red minus sign.
Run - Edit Configurations - 选中 Application 下需要配置的项 - 右侧 Configuration 选项 - 配置 Environment variables - 添加环境变量即可。
Run - Edit Configurations - xxx - Right:Configuration - Environment variables
enter image description here
Related
When I run Gradle tasks like test from IntelliJ, I set VM options and/or environment variables for all tests in "Edit configuration" dialog and they work. See my question at how to set spring.config.location for a gradle spring boot project in Intellij IDEA community version?
Now, if I want to run a single test, I must:
run test, which fails of course
edit configuration to add VM options and/or env vars
run it again
Is there some way to configure the VM options and/or env vars in build.gradle so that would be picked up by every single test automatically?
PS: the args are -Dspring.profiles.active=... and -Dspring.config.additional-location.
Try setting the system properties in the file gradle.properties like so:
systemProp.spring.profiles.active=profileName
spring.config.additional-location=additionalLocation
See also: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties
Thanks #tarts, but I think I have found one thing maybe better: setting a template of run configuration in IDEA. The question may be reworded into: "can I in some way, not limited in build.gradle, to set these variables?"
In "Run Configuration", on the left side, there is a category named "Template" listing all possible categories of tests we can run and providing template for each, where we set universal values for single tests.
You can see that "Gradle" and "JUnit" and other many categories are listed, so we can change VM options here, then all unit tests are run with this param set.
I'm using IntelliJ IDEA to write and run e2e tests with JUnit. My tests require some environment variables to be set, so I set these in the Run Configurations dialog (through Run-->Edit Configurations, Environment Variables field).
This works fine, but the problem is whenever I run a single test (e.g. by clicking the green "play" icon to the left of the code editor), it creates a new run configuration for me to run this single test without the environment variables I defined, which obviously causes it to fail. I need to open the Run Configurations dialog again and copy the environment variables from another configuration to the new one. Note that I need to do it for every single test that I run, which is very annoying.
Is there a way to set the environment variables only once and use them for every test that I run?
You can expad the "Defaults" in the list to the left, pick JUnit and then set the env variables there. This config will then get copied to whatever new configurations are created afterwards:
Is there a way to set System Properties which are used for every JVM that is started by NetBeans (NB 7.3.1 on Win 7)?
In all my maven projects I use Log4j wich needs a log4j.properties file, to where I want to point to by a System Property -Dlog4j.configuration=file:/c:/log4j/log4j.properties
I could set Global Execution Options for Maven: Tools > Options > Java > Maven > Global Execution Options. But then when I run a particular JUnit test class in NetBeans (thus without Maven), NetBeans won't use these JVM System Properties set in the Global Execution Options field.
Same issue is when a Main class in a Maven module is run in NetBeans. To set JVM System Properties there are Project Properties which could be set: 'Main Class' and 'VM Options'. But these Project Properties are only used by NetBeans when the 'Run' command is used from the context menu of the maven module. (Unfortunaly this menu item doesn't have a shortcut key (normaly Shift-F6)).
I have worked around this by setting a System Variable JAVA_TOOL_OPTIONS=-Dlog4j.configuration=file:/c:/log4j/log4j.properties.
Edit
A question was asked for the same problem I ran in to: How to make Netbeans use specific JVM parameters when running tests? In my case the problem was caused by the option Compile on Save which I had swiched on (File > Project Properties > Build > Compile > Compile On Save). In that case it seems that NetBeans doesn't use Maven. For further info about CoS: http://wiki.netbeans.org/FaqCompileOnSave
There's a file called project.properties in the nbproject folder. In this file there is a lot of configurations you can do that are not in the GUI menus. I don't know exactly what to put there to achieve what you want, but I found this on one of my NetBeans projects config:
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
I'm writing a Java library with a lot of jni code. Pretty much every test case needs to load my jni dll, and I have a lot of test cases. In order to run the test cases out of Eclipse's Junit launcher, I have to create a run/debug configuration and edit the VM arguments and environment variables.
I would like a way to set the VM arguments and environment variables to a default for the entire project and have new run configurations include the default entries. From what I can tell, Execution Environments maybe do something like this but I seem to need the PDE to get them to work(?)
Specifically, I want to enable assertions on my project by default and include the path to my native dll in the PATH environment variable. I can't use the "Default VM Arguments" setting in the JRE definition panel because my dll depends on a number of others and java.library.path isn't used for dependency resolution, PATH is. Is there a way to make Eclipse do what I want?
So, here's what I did.
First, my specific problem was that I have a lot of run configurations, I create new ones on the fly, and I needed certain system properties set for unit tests. Setting them under the 'args' tab of run configurations was undesirable for my workflow. Also, I wanted the same command-line args set for all of my tests. I also don't run my app from inside eclipse. It's a dev-environment only.
So my solution was to add it to the command-line of my JRE. Preferences -> Java -> Installed JREs. Clicking edit gives you a window where you can specify default VM args. I just set the system properties I need for testing there.
Hope this helps.
How long does it take to run all of your tests for the project?
If the answer is Not long then create a project-wide JUnit launcher. If occasionally you would need to do a run on a single test case ( in order to debug or something ), you can copy all your settings from the project's junit launcher. I think you can even clone your project launcher to run a specific test case.
Run->Run Configurations...
Create new JUnit launcher.
On 'Test' tab select Run all tests
in selected {...}
Connfigure JVM options, classpath,
environment etc. for this launcher
Optional, but highly recommended. On
Common tab -> Save as -> Shared
file, and check-in launcher with
your project
One more thing I would do is to define a system property in launcher VM arguments, check for this property in #Before function and throw exception if the property is not set. This way you will know that your test fails because it is not using the right launcher.
If I understand your question correctly, I think Alexander is on to the idea with cloning the project launcher. Eclipse lets you duplicate launch configurations with a single click - simply setup one configuration with the parameters you require and click the button in the top left to duplicate it whenever you create a new one.
When I implement new features using TDD, I often use the shortcut Shift + Alt + D T to run only the jUnit test case I am currently working on (and not the whole test suite, which takes a few minutes).
This creates a new Debug Configuration for the current Java source and runs it immediately. Now I would like to run the test with assertions enabled (VM option -ea).
Unfortunately, the VM arguments for the new debug configuration starts empty. I always have to go into Debug Configurations... → Arguments and add -ea to the VM arguments input box.
Is there any way to have Eclipse these arguments populated with (project or workspace wide) default options?
I think you can set this option by editing the definition of the JRE under Preferences → Java → Installed JREs → Select the JRE in question and edit the default VM arguments
Windows → Preferences → JUnit has an option to add -ea every time a new launch configuration is created. It adds the -ea option to the Debug Configuration as well.
The full text next to a check box is:
Add -ea to VM arguments when creating a new JUnit launch configuration
Only way I can see to do it is to contribute a new launch configuration, this is not a trivial task but not too hard if you have PDE experience.
There is an eclipse.org article (see "Creating a Launch Configuration") that describes how to construct configurations and launch them.
I guess you could copy the JUnit implementation (see the org.eclipse.debug.core.launchConfigurationTypes extension in org.eclipse.jdt.junit) and add in your chosen defaults to that config. You'd then need to declare a key binding to launch it and package the plugin to your install.