Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing JUnit command line parameters in eclipse

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?

like image 629
Virat Kadaru Avatar asked Mar 25 '09 22:03

Virat Kadaru


People also ask

How do you pass command line arguments in JUnit?

getAbsolutePath(); String[] arguments = new String[1]; arguments[0] = filename; // now call your constructor myClass obj = new myClass(arguments); // do any checks here now Assertions. assertTrue(obj. getWhatever()); // ... } Save this answer.


2 Answers

You cannot pass command line arguments to the JUnit test because 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.

Alternatively, with the desired project as your current one, from the main menu select Run -> Run Configurations to access the Arguments tab.

like image 76
Mark Avatar answered Oct 10 '22 23:10

Mark


I will skip passing as somebody has already replied with that. To access you use:

System.getProperty("propert.name.here");

(returns String)

like image 38
Cukierpudel Avatar answered Oct 11 '22 01:10

Cukierpudel