首页 > 解决方案 > 无法将参数从 maven 命令传递到 Testng Runner

问题描述

我的测试跑步者

@Parameters("exeenv")
@BeforeClass
public void beforeClass(ITestContext context, String exeenv) {

 System.out.println("Testng Value before class=> " + exeenv);
}


@Parameters({
 "exeenv"
})
@Test
public void run(String exeenv) {
 System.out.println("Testng value at run " + exeenv);
 super.run();
}   

我的POM:

<build>
   <plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-failsafe-plugin</artifactId>
      <version>2.19.1</version>
      <configuration>
         <parallel>classes</parallel>
         <threadCount>3</threadCount>
         <testFailureIgnore>true</testFailureIgnore>
         <systemPropertyVariables>
            <testconfig>${testconfig}</testconfig>
            <exeenv>${exeenv}</exeenv>
            <browser>${browser}</browser>
            <uitest>${uitest}</uitest>
         </systemPropertyVariables>
         <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
         </suiteXmlFiles>
         <!-- <includes>
            <include>**/ExecutionRunner.java</include>
            </includes> -->
      </configuration>
      <executions>
         <execution>
            <goals>
               <goal>integration-test</goal>
               <goal>verify</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</build>

我的命令:

mvn clean verify -Dexeenv=dev

我的输出:

Testng Value before class=> QA
Testng value at run=> QA

我在 maven 命令中将 exeenv 值作为 dev 传递,但我总是在输出中只看到 QA。有人可以帮忙吗

标签: javamaventestng

解决方案


从文档:

我们可以通过两种方式为 testng 测试提供参数值。

通过 testng.xml XML 配置文件和通过 DataProviders

您可能想尝试System.getProperty从命令行读取环境


推荐阅读