tags:

views:

300

answers:

3

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?

A: 

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.

  1. Run->Run Configurations...
  2. Create new JUnit launcher.
  3. On 'Test' tab select Run all tests in selected {...}
  4. Connfigure JVM options, classpath, environment etc. for this launcher
  5. 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.

Alexander Pogrebnyak
Duplicating and then editing a test case is less work than creating one from scratch. It's not quite what I hoped for, but based on what's been discussed so far, it's the most feasible answer.
gibbss
A: 

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.

Sam Brightman
A: 

sorry, just saw that you can't use my suggested fix

Stevicus