为了将命令行参数传递给 pom.xml 文件中的 Maven 属性,您需要使用 ${} 语法来引用属性并使用 -D 选项在命令行上设置它们的值。
在您的情况下,您可以修改 maven-surefire-plugin 配置中的 testnames 属性以使用 ${} 语法,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>testnames</name>
<value>${testnames}</value>
</property>
</properties>
</configuration>
然后,在命令行上,您可以使用 -D 选项设置 testnames 属性的值,如下所示:
mvn clean test -Dtestnames=iOS
这应该覆盖 pom.xml 文件中设置的默认值,并使用在命令行上传递的值。