I recently used junit in eclipse and I am still involved. I know how to pass command line options in eclipse, but how to pass them to a test case in Junit? Also, how do I access them?
You cannot pass command line arguments to the JUnit test because the main method does not start. You will need to use the system properties and access them in a test case.
Select a test class in the Package Explorer. Right-click and select Run As -> Open Run Dialog . The run dialog has an Arguments tab where you can specify the arguments of the program and the virtual machine. Here you must enter the parameters of your system.
Run As -> Open Run Dialog
Alternatively, with the desired project as the current one, select Run -> Run Configurations from the main menu to go to the "Arguments" tab.
Run -> Run Configurations
I will skip the passage, as someone has already answered with this. To access you use:
System.getProperty("propert.name.here");
(returns a string)
You probably understood this, but when compiling and using ANT or MVN, you can pass arguments to JUNIT or TestNG from the POM.XML file.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.3</version> <configuration> <forkMode>${test.junit.forkMode}</forkMode> <skip>${test.junit.skip}</skip> <argLine>${test.junit.argLine}</argLine> <jvm>${jdk.compiler.path}/binjava</jvm> </configuration> </plugin>
In this example, I pass the webDriver argument as firefoxDriver in the launch configuration window:
webDriver
firefoxDriver