TestNG is using a program argument that is intended for the code of my test, not for TestNG

829 views Asked by At

In a TestNG test running in Eclipse Neon.2, I need the code of my test to access a program argument that I set in the Run Configuration of the test. This does work, but the problem is that TestNG itself uses that argument, apparently thinking it represents some file; so when the test runs, the first thing that appears in the Eclipse console is:

java.io.IOException: The filename, directory name, or volume label syntax is incorrect
  at java.io.WinNTFileSystem.canonicalize0(Native Method)
  at java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:428)
  at java.io.File.getCanonicalPath(File.java:618)
  at org.testng.xml.Parser.parse(Parser.java:151)
  at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
  at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
  at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
  at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

I set that argument in the Run Configuration for the test, in the "Arguments" tab, under "Program arguments". The argument is homepath=C:/MyFolder and it's the only one. No args are set in "VM arguments".

Is there a way to tell TestNG to ignore a certain program argument ?

The TestNG plugin is ver. 6.8.6.20141201_2240, Windows 8.1.

1

There are 1 answers

0
XuQing Tan On BEST ANSWER

if you create 'Run Configuration' for TestNG, the "Program arguments" is used for TestNG, not your app. so in case your app need some context alike command line argument, you can pass with -Dfoo=bar in "VM arguments", or with environment variables, and in your app to get them by calling System.getProperty(), or System.getenv()