【问题标题】:TestNG is using a program argument that is intended for the code of my test, not for TestNGTestNG 正在使用一个用于我的测试代码的程序参数,而不是用于 TestNG
【发布时间】:2017-01-02 16:37:26
【问题描述】:

在 Eclipse Neon.2 中运行的 TestNG 测试中,我需要测试代码来访问我在测试的运行配置中设置的程序参数。这确实有效,但问题是 TestNG 本身使用该参数,显然认为它代表某个文件;所以当测试运行时,Eclipse 控制台中首先出现的是:

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)

我在“程序参数”下的“参数”选项卡的“运行配置”中为测试设置了该参数。参数是homepath=C:/MyFolder,它是唯一的一个。 “VM 参数”中未设置任何参数。

有没有办法告诉 TestNG 忽略某个程序参数?

TestNG 插件是版本。 6.8.6.20141201_2240,Windows 8.1。

【问题讨论】:

    标签: java eclipse testng testng-eclipse


    【解决方案1】:

    如果您为 TestNG 创建“运行配置”,则“程序参数”将用于 TestNG,而不是您的应用。 因此,如果您的应用程序需要一些类似上下文的命令行参数,您可以在“VM 参数”或环境变量中使用-Dfoo=bar 传递,并在您的应用程序中通过调用System.getProperty()System.getenv() 来获取它们

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多