Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

junit

eclipse

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

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

enter image description here

like image 759
James Raitsev Avatar asked Mar 23 '12 00:03

James Raitsev


People also ask

How do I set environment variables permanently?

To make permanent changes to the environment variables for all new accounts, go to your /etc/skel files, such as . bashrc , and change the ones that are already there or enter the new ones. When you create new users, these /etc/skel files will be copied to the new user's home directory.

How do I set environment properties in JUnit?

The @ClearEnvironmentVariable and @SetEnvironmentVariable annotations can be used to clear, respectively, set the values of environment variables for a test execution. Both annotations work on the test method and class level, are repeatable, combinable, and inherited from higher-level containers.


2 Answers

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

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

like image 151
James Raitsev Avatar answered Oct 21 '22 20:10

James Raitsev


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

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

This will spawn eclipse with proper environment settings.

like image 35
Logan Waggoner Avatar answered Oct 21 '22 21:10

Logan Waggoner