java - 无法将参数从 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。有人可以帮忙吗
解决方案
从文档:
我们可以通过两种方式为 testng 测试提供参数值。
通过 testng.xml XML 配置文件和通过 DataProviders
您可能想尝试System.getProperty
从命令行读取环境
推荐阅读
- python - 我可以获得在运行时传递给我的 python 函数的内容的 AST 表示吗?
- python - 如何让我的循环停止迭代,以便在错误为 10^-6 时停止
- react-native - 在 React Native 中单击 3 个点时打开菜单的更好解决方案
- ios - Swift:在应用程序处于后台时调用 .requestLocation()
- python - 如何在python中使文本可点击
- php - 如何从此 DOMobject 获取“价格和图像键”值
- php - 加载并显示 foreach 元素,稍等,加载下一个,依此类推
- php - 如何摆脱页脚下方的这个额外部分 - Bootstrap
- highcharts - 自定义 Sankey Highcharts 标记和链接宽度
- java - Spring MVC 和 Thymeleaf - 迭代多个项目时 th:value 和 th:field 有什么区别?