James Raitsev
James Raitsev

Reputation: 96391

How to set up environment variable for all tests in 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

Upvotes: 12

Views: 13252

Answers (3)

inger
inger

Reputation: 20184

I also find it frustrating having to set env vars one by one. If you own the code and have a chance to change it, you'd be better off using a System property instead, which can be passed as VMArgs -Dprop=val.

You can set VM args in a global level - Preferences | Java | Installed JREs, and Plugin Development | Target platform.

Even if you can't change the code, most well civilised java libs support properties as well if not more than env vars- so it's worth double checking. (of course it's not an option for external processes).

Upvotes: 0

Logan Waggoner
Logan Waggoner

Reputation: 71

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.

Upvotes: 2

James Raitsev
James Raitsev

Reputation: 96391

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

Upvotes: 4

Related Questions