简体   繁体   English

如何使用Maven在TestNG套件xml文件中的多个类中运行测试类?

[英]How to run a test class from multiple classes in a TestNG suite xml file using maven?

My question is actually a duplicate of How do I tell Maven and TestNG to run a specific test class and suite.xml file? 我的问题实际上是如何告诉Maven和TestNG运行特定的测试类和suite.xml文件的副本。 but I did not understand the accepted answer so asking again. 但我不理解被接受的答案,因此再次询问。

I have the same problem, when I try to run a particular suite using clean test -DsuiteFile=Suites\\Jquery.xml it runs that suite which is fine. 我有同样的问题,当我尝试使用clean test -DsuiteFile=Suites\\Jquery.xml运行特定套件时,它会运行该套件,这很好。 also clean test -Dtest=WebGuru99_2 runs that test class but when I try doing clean test -DsuiteFile=Suites\\Jquery.xml -Dtest=WebGuru99_2 , it runs that class but it doesn't depend on the suite file now. 还要进行clean test -Dtest=WebGuru99_2运行该测试类,但是当我尝试进行clean test -DsuiteFile=Suites\\Jquery.xml -Dtest=WebGuru99_2 ,它将运行该类,但现在不依赖于套件文件。 I can give any suite file here and it will run the same test class, which defeats the purpose of having suite file. 我可以在此处提供任何套件文件,它将运行相同的测试类,这违背了拥有套件文件的目的。

POM.xml POM.xml

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <suiteFile></suiteFile>
  </properties>

  <dependencies>
   <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.35.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.35.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
  </dependencies>
  <build>
        <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${suiteFile}</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
</build>

This is because -Dtest overrides -DsuiteFile (-Dtest also overrides "include" and "exclude" methods in testng.xml ). 这是因为-Dtest覆盖了-DsuiteFile(-Dtest也覆盖了testng.xml中的“ include”和“ exclude”方法)。 So "clean test -DsuiteFile=Suites\\Jquery.xml -Dtest=WebGuru99_2" will always run WebGuru99_2 test and -DsuiteFile will be ignored. 因此,“干净测试-DsuiteFile = Suites \\ Jquery.xml -Dtest = WebGuru99_2”将始终运行WebGuru99_2测试,而-DsuiteFile将被忽略。

I doubt if "clean test -Dtest=WebGuru99_2" will run or not as you have to give the -DsuiteFile=Suites\\Jquery.xml also as configured in pom 我怀疑“干净测试-Dtest = WebGuru99_2”是否会运行,因为您必须按照pom中的配置给-DsuiteFile = Suites \\ Jquery.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何告诉Maven和TestNG运行特定的测试类或suite.xml文件? - How do I tell Maven and TestNG to run either a specific test class or a suite.xml file? 如何使用 Selenium/TestNG/Maven 运行单个测试用例(方法)而不是整个测试套件(类) - How to run a single test case (method) instead of whole test suite (class) using Selenium/TestNG/Maven 如何使用Jenkins中的maven从多个套件运行特定的TestNG套件 - How to run a particular TestNG suite from multiple suites using maven in Jenkins 从testng.xml文件中的其他路径运行测试类 - run test classes from other path in testng.xml file 如何在java上使用maven按顺序运行具有多个testng测试的多个类 - How to run a multiple class with multiple testng test in sequential order using maven on java 如何在testng套件中的单个测试标签下运行一组类? - How to run a set of classes under single test tag in testng suite? 使用testng.xml使用maven运行单个TestNG测试 - Run single TestNG test with maven by using testng.xml 如何从批处理为maven项目运行testng .xml文件 - How to run a testng .xml file from batch for a maven project TestNG + Maven,如何在使用mvn test调用TestNG.xml之前运行代码块? - TestNG+Maven, how to run a block of code before calling the TestNG.xml using mvn test? 如何从 Maven 运行 testng.xml? - How to run testng.xml from Maven?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM