我正在尝试使用 TestNG 和 Maven Surefire 运行测试。我可以使用
mvn test
运行测试,但我想向它传递 TestNG 命令行参数,例如 -testnames
或 -groups
.
换句话说,我想做
java org.testng.TestNG -groups windows,linux -testclass org.test.MyTest
的等价物,但使用 Maven mvn test -groups windows,linux -testclass org.test.MyTest
.
我尝试使用像
mvn test -Dgroups groupA
这样的东西,但那没有用
更具体到我的情况我有一个 testng.xml 有两个测试标签,每个测试不同的移动操作系统。默认
mvn test
并行运行它们,但有时我只想运行一个设备 mvn test -testnames Android
。我宁愿避免为这样一个简单的用例制作多个 XML。
我的testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automation Test" parallel="tests" thread-count="2">
<test name="iOS">
<parameter name="deviceOS" value="iOS"/>
<classes>
<class name="runner.RunParallelTests"/>
</classes>
</test>
<test name="Android">
<parameter name="deviceOS" value="Android"/>
<classes>
<class name="runner.RunParallelTests"/>
</classes>
</test>
</suite>
我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>App</groupId>
<artifactId>App-Test-Automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
[...]
</dependencies>
</project>
觉得没必要知道,但我也在用 Appium 和 Cucumber 写测试。