I have recently been using junit in eclipse and I am still learning. I know how to pass command line parameters in eclipse, but how do I pass them to a test case in Junit? Also how do I access them?
+2
A:
You cannot pass command line arguments as normal to the JUnit test as no main method is run. You will need to use system properties and access these in your test case.
Select your test class in the Package Explorer. Right click and select Run As -> Open Run Dialog. In the run dialog there is an Arguments tab where you can specify program and VM arguments. You should be able to enter your system property parameters here.
Mark
2009-03-25 23:34:58
But if I use eclipse, I do not need a main method to run my test. How do I access them without setting them in system properties?
Virat Kadaru
2009-03-26 00:04:03
It seems that with JUnit4 and Eclipse your only option is system properties. I have edited my answer to reflect this.
Mark
2009-03-26 09:35:52