Passing JUnit command-line options to eclipse

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?

+4
command-line eclipse junit
source share
4 answers

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.

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

+11
source share

I will skip the passage, as someone has already answered with this. To access you use:

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

(returns a string)

+6
source share

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> 
+2
source share

In this example, I pass the webDriver argument as firefoxDriver in the launch configuration window:

Example

+2
source share

All Articles