代码之家  ›  专栏  ›  技术社区  ›  Virat Kadaru

在Eclipse中传递JUnit命令行参数

  •  5
  • Virat Kadaru  · 技术社区  · 16 年前

    我最近在Eclipse中使用了junit,现在我还在学习。我知道如何在Eclipse中传递命令行参数,但如何将它们传递给JUnit中的测试用例?我如何访问它们?

    4 回复  |  直到 8 年前
        1
  •  11
  •   arkon    12 年前

    无法将命令行参数传递给JUnit测试,因为没有运行主方法。您将需要使用系统属性并在测试用例中访问这些属性。

    在包资源管理器中选择测试类。右键单击并选择 Run As -> Open Run Dialog 在运行对话框中有一个参数选项卡,您可以在其中指定程序和VM参数。您应该能够在这里输入系统属性参数。

    或者,将所需项目作为当前项目,从主菜单中选择 Run -> Run Configurations 访问参数选项卡。

        2
  •  6
  •   Cukierpudel    14 年前

    我会跳过过去,因为有人已经回答过了。 要访问,请使用:

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

    (返回字符串)

        3
  •  2
  •   Amir    14 年前

    可能您已经解决了这个问题,但是在编译和使用Ant或MVN时,您可以从pom.xml文件内部将参数传递给JUnit或testng。

     <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>
    
        4
  •  2
  •   Obsidian Age    8 年前

    在这个例子中,我正在传递一个参数 webDriver 作为 firefoxDriver 在运行配置窗口中:

    Example