我想通过maven和命令行运行test.xml
文件。我的test.xml
有4个班级,但不幸的是,他们有{4}个班级。命令只挑选一个类。
以下是pom.xml
<groupId>com.mobikon.commontestapp</groupId>
<artifactId>commontestapp</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>test.xml</suiteXmlFile>
</suiteXmlFiles>
<!--<workingDirectory>target/</workingDirectory>-->
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
以下是test.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Mobikon Automation Tests" verbose="1" >
<test name="mEngage" >
<classes>
<class name="mengage.tests.LoginScenarios"></class>
<class name="mengage.tests.PurchaseCreditsTest"></class>
<class name="mengage.tests.VerifyTotalCustomers"></class>
<class name="mengage.tests.VerifyCredits"></class>
</classes>
</test>
</suite>
所以现在如果我从命令行运行maven,这就是输出。它只接受PurchaseCredits类。
命令 - mvn clean test
如果我直接从IntelliJ运行它运行正常,那么我面临的唯一问题是我无法从maven运行正确的test.xml
文件
在mvn -Ptest清理测试之后,这是Maven的截图 enter image description here
答案 0 :(得分:2)
您必须激活激活相应surefire
配置的配置文件:
mvn -Ptest clean test
默认情况下,surefire
仅运行Test*
和*Test
个类。这就解释了为什么在您的情况下只采用PurchaseCreditsTest
。