我目前正在使用WebDriver,TestNG和Maven来运行一个小型测试框架。在这个框架中,我想传递一套测试,偶尔,如果不是所有测试都需要运行,只想运行测试套件中列出的测试组中的特定测试。
mvn clean install -Dsuite=smokeTests -Dgroups=loginTest -Denv=qa-env -Dusr=username -Dpwd=password
但是,当我使用具有多个测试的测试套件运行上述行时,它将使用该套件执行所有测试。更奇怪的是,如果我要在测试套件中调用第二组,它将跳过第一个测试按预期执行第二个,但也会执行剩余的测试。 POM和示例测试套件如下。
POM:
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>**/*.java</include>
<include>**/*.xml</include>
</includes>
<groups>${groups}</groups>
<suiteXmlFiles>
<!-- suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile-->
<suiteXmlFile>src/main/resources/suites/${suite}.xml</suiteXmlFile>
</suiteXmlFiles>
<testSourceDirectory>src/main/java</testSourceDirectory>
<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>
</configuration>
</plugin>
</plugins>
</build>
...
POM依赖
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.34.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.34.0</version>
</dependency>
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.3</version>
<!-- http://jira.codehaus.org/browse/JAXEN-217 -->
<exclusions>
<exclusion>
<groupId>maven-plugins</groupId>
<artifactId>maven-cobertura-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>maven-plugins</groupId>
<artifactId>maven-findbugs-plugin</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<!--scope>test</scope-->
</dependency>
</dependencies>
Test Suite .xml
<suite name="SmokeTest" verbose="10" parallel="tests" data-provider-thread-count="5">
<test name="loginTest">
<classes>
<class name="com.tests.smoke.WebPage_LandingPage" />
</classes>
<groups>
<run>
<include name="loginTest"/>
</run>
</groups>
</test>
<test name="paginationTest">
<classes>
<class name="com.tests.smoke.WebPage_Pagination" />
</classes>
<groups>
<run>
<include name="paginationTest"/>
</run>
</groups>
</test>
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<!--listener class-name="org.uncommons.reportng.JUnitXMLReporter" /-->
</listeners>
</suite>
答案 0 :(得分:1)
正如我在上面的评论中所说的那样,我今天决定更多地考虑这个问题,并认为我会调整直接影响我的测试调用的各个依赖项。在尝试了不同版本的jUnit并且没有得到任何地方后,我决定恢复到旧版本的TestNG,我曾在一个较旧的项目中使用过。
更改为:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.0.1</version>
<scope>compile</scope>
</dependency>
这允许用户输入以下maven语句以仅执行被调用的测试组
mvn clean install -Dsuite=<Smoke> -Dgroups=<testgroup1> -Denv=<thisisanEnvironment> -Dusr=<username> -Dpwd=<password>
我希望这可以帮助其他可能陷入同样情况的人。谢谢。