[英]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.