Eclipse - passing VM parameter to every test in the project - java

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.
Thank you for help.

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.
Now simply configure your project to use this JRE (Java Build Path) and you should be on the right way.

Eclipse have already a built-in JUnit for you.
You can use JUnit to run different parameters on your main program.

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.
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.

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.

Related

IntelliJ IDEA does not see my environment variables

I've configured an environment variable in ~/.bashrc as well as ~/.profile.
When I run my application via IDEA's Gradle Configuration, my environment variable is apparently not available. E.g. I am referencing this variable within application.yml, but the default value is being used instead. Running Gradle from the command line correctly picks up my variable.
How can I configure IDEA to load this environment variable in a global way, so I don't have to manually add it to every project where I need it (~20 projects)?
Note: running on Manjaro Linux v18.
It turns out IDEA will pick up environment variables if you define them either in e.g. /etc/environment or /etc/profileor if you use ZSH,~/.zshrc`.
After setting variables, you to execute source ~/.bashrc and source profile to update and execute the file contents.
# josh-m I ran into the same problem in my IntelliJ IDEA setup with Maven.
In the end, I continued to keep the settings on each project, as there were not many, but when I studied the problem I found this IntelliJ support link:
https://youtrack.jetbrains.com/issue/IDEA-141832
At least at that time, this functionality was not available in IntelliJ directly, although the following plugin, mentioned in the comments of the support article, could perhaps be of some help:
https://plugins.jetbrains.com/plugin/7861-envfile/
launchctl setenv HADOOP_VERSION 3.1.1.7.2.8.0-SNAPSHOT
Execute in this way to set your environment variables in MacOS for them to be used by other applications.
After that restart your IDE.

Eclipse IDE: Run configurations and switching default JVM arguments

I'm looking for some way to switch between default VM arguments. I've got a workspace with a bunch of projects and created run configurations for running JUnit tests. I'm able to switch between run configurations easily.
In order to run any test correctly, I need to pass some arguments to JVM. This is problem whenever I want to run a specific test method SHIFT+ALT+X,T. Since it creates a whole new Run Configuration, it doesn't pass any VM arguments to it.
I figured out how to set default VM arguments using Window -> Preferences -> Java -> Installed JREs -> Edit -> Default VM arguments. This, however, means that whenever I need to switch to different VM arguments, I'd have to do it manually.
What I'd need in the most optimal case is some select box visible on the toolbar, where I could switch between global run configurations from which all newly created ones would "inherit".
I'd also like to see a way to make automatically created run configurations destroy themselves as soon as I switch to a different one, because at this point, I have 36 run configurations (which I manually created) and I don't want to see a "garbage" from each test method I executed. Over the time, there might be thousands of Run Configurations in between which I'd have to search. I don't want to spent few minutes a day deleting them.
So, the recapitulation:
Is there a way to easily switch between default VM arguments?
Is it possible to keep the list of Run Configurations clear, meaning it will only contain run configurations I created?

How to make Netbeans use specific JVM parameters when running tests?

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):
-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.
Is there a way to change the JVM parameters used by Netbeans when it runs tests that way?
This is somewhat similar to this other post but my question is specific to Netbeans.
From the documentation of Netbeans 7.2 (see Netbeans 7.2 changes, section Maven) :
... Now Test File always runs Maven by default, just like Test Project ...
What version of Netbeans are you using? Probably you should just upgrade to 7.2.
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.
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.
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...

Automate Runs in Eclipse

I have a main class that takes a series of arguments and I have 10 run configurations. Is there a way to have eclipse run them one after another?
The other answers are probably better solutions to your problem. However, if you install the Eclipse CDT into your Eclipse installation (using update manager or market place client), then you get an additional launch configuration type called Launch group.
Those launch groups allow creating a list of other launch configurations to be run one after the other. Make sure to set the Post build action in the dialog to "Wait until terminates" for each included launch configuration.
#Steven: To do it quick, you can write a JUnit Test case that just calls the intended classes in desired order and execute it. Eclipse already has the necessary jar for JUnit, so you are ready to go. Definitely, writing ANT/MAVEN script is a good practice.
As #gotuskar suggested, write test cases for your class. If you can afford running your ten configurations each time you build your project put them in its src/test/java directory, otherwise create a sibling project to your original one, make it depend on it, and put your tests there.

How can I retrieve environment variables(Jenkins) in java

I'm setting some environment variables by some windows batch commands in the pre-build steps for a Jenkins build. I need to use these variables for a few java selenium test cases which will run during as part of the build.
set HD_KF_TC_IN_LOOK_UP_KET_FEATURE_XLS = %WORKSPACE%\selenium_input_files\Key_Features\en_US
I have tried to retrieve these environment variable values by using System.getEnv(HD_KF_TC_IN_LOOK_UP_KET_FEATURE_XLS) commands. But this is not working as the values for these variables is always NULL.
Please let me know where I'm I going wrong?
As indicated in my comment, I do not completely understand your setup. In general, however, environment variables set in one Jenkins build step do not propagate outside of it and can't be accessed from other build steps. You need to use EnvInject plugin to achieve that.

Categories

Resources