Passing JUnit command line parameters in eclipse

2019-02-17 16:07发布

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?

4条回答
再贱就再见
2楼-- · 2019-02-17 16:25

In this example I am passing an argument webDriver as firefoxDriver in the run configuration window:

Example

查看更多
姐就是有狂的资本
3楼-- · 2019-02-17 16:28

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

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

(returns String)

查看更多
不美不萌又怎样
4楼-- · 2019-02-17 16:29

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.

查看更多
Explosion°爆炸
5楼-- · 2019-02-17 16:30

Probably you have figured this out, but when compiled and if using ANT or MVN, you can pass arguments to your JUNIT or TestNG from inside 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>
查看更多
登录 后发表回答