代码之家  ›  专栏  ›  技术社区  ›  Saikat SHASHANK HONRAO

Maven surefire插件没有为testng选择组选项

  •  3
  • Saikat SHASHANK HONRAO  · 技术社区  · 8 年前

    我有一个带有以下注释的testng用例-

    @Test(groups="groupA", dataProvider="DataSet1")

    但当我触发以下maven命令时,它不会执行测试-

    mvn test -Dgroups=groupA

    我在控制台中看到的只是这个-

    ...
    ...
    [INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ abc-proj ---
    
    -------------------------------------------------------
    T E S T S
    -------------------------------------------------------
    Running TestSuite
    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.733 sec -      in TestSuite
    
    Results :
    
    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
    

    但是当我只是跑的时候 mvn test 它执行测试。不知道为什么会这样。我正在使用Surefire插件版本 2.19.1 6.9.9 . 任何帮助都将不胜感激。

    编辑 我没有使用testng。只是出于好奇,我在一个小项目中尝试了同样的事情->它起作用了。在那个项目中,我创建了一个示例类-

    import org.testng.annotations.Test;
    
    public class SampleTest {
    
        @Test(groups = "groupA")
        public void testA() {
            System.out.println("Inside A");
        }
    
        @Test(groups = "groupB")
        public void testB() {
            System.out.println("Inside B");
        }
    
    }
    

    pom.xml 是-

    ... 
    <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.9</version>
            </dependency>
        </dependencies>
    </project>
    

    这是命令 mvn测试-Dgroups=groupA 很好!

    编辑2 当我移除 dataProvider “我注意到了一些不同的结果,”控制台现在说-

    Tests run: 1, Failures: 0, Errors: 0, Skipped: 1

    3 回复  |  直到 8 年前
        1
  •  1
  •   Naman    8 年前

    要做到这一点,您可能需要将测试分组到surefire配置中:-

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <groups>ABC,XYZ</groups>
        </configuration>
    </plugin>
    

    然后执行

    mvn test -Dgroups=ABC
    
        2
  •  0
  •   Saikat SHASHANK HONRAO    8 年前

    找到了此问题的根本原因。在这里 testng 正在运行 @DataProvider 方法 first @BeforeClass 方法和我在这两者之间有依赖关系(我假设@BeforeClass将首先运行)。然而,当我一次运行所有测试时,这不会引起任何问题,但当我尝试基于 groups .

        3
  •  0
  •   user13977088    5 年前
        This works for me: 
        Tests:
             @Test(groups = "Regression")
             public void testOne(){
             System.out.println("Regression");}
        
             @Test(groups = "Functional")
             public void testTwo() {
             System.out.println("Functional");
             }
        
        use this in pom.xml
        
            <build>
            <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>3.0.0-M5</version>
              <configuration>
                <suiteXmlFiles>
                  <suiteXmlFile>run.xml</suiteXmlFile>
                </suiteXmlFiles>
              </configuration>
            </plugin>
            </plugins>
            </build>'
    
    
    
    run.xml file: 
       
    
         <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
        
            <suite name="Suite1" verbose="1" >
            <test name="TestingGroups" >
                <classes>
                    <class name="test.GroupsTesting"/>
                </classes>
            </test>
            </suite>'
    
    command to run Functional test cases :mvn test -Dgroups=Functional