我正在尝试使用命令 mvn clean test -Dgroups=group2,smoke 执行。它执行所有 4 个测试用例。
但是如果我使用 mvn clean test -Dgroups=group2 它执行 Test1 和 Test 2(如预期的那样)。
问题是我有大约 24 个组组合,所以为每个组更新 testNg.xml 似乎不是我的选择。
我正在使用 JAVA、TestNg 和 Maven
我在这里错过了什么?
测试代码:
public class myTests extends Basetest {
@Test(groups = {"group1","group2", "group3","regression", "smoke","sanity"})
public void Test1() {
System.out.println(" Test 1");
}
@Test(groups = {"group1","group2", "regression", "smoke","sanity"})
public void Test2() {
System.out.println(" Test 2");
}
@Test(groups = {"group1", "group3","regression", "smoke","sanity"})
public void Test3() {
System.out.println(" Test 3");
}
@Test(groups = {"group1","regression", "smoke","sanity"})
public void Test4() {
System.out.println(" Test 4");
}
}
基础测试
public class Basetest {
@BeforeMethod
public void myConfig(){
System.out.println("Before Method ");
}
@AfterMethod
public void tearDown(){
System.out.println("After Method ");
}
}
testNg xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="bik.Test.myTests"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Maven pom
<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>bik</groupId>
<artifactId>Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test</name>
<url>http://maven.apache.org</url>
<properties>
<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.11.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>