1

我目前正在使用 WebDriver、TestNG 和 Maven 来运行一个小型测试框架。在这个框架中,我想通过一组测试,偶尔,如果不是所有的测试都需要运行,我只想从测试套件中列出的测试组中运行一个特定的测试。

mvn clean install -Dsuite=smokeTests -Dgroups=loginTest -Denv=qa-env -Dusr=username -Dpwd=password

但是,当我使用包含多个测试的测试套件运行上述行时,它将使用该套件执行所有测试。更奇怪的是,如果我要调用测试套件中的第二组,它将按预期跳过第一个测试以执行第二个测试,但也会执行剩余的测试。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>

测试套件 .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>
4

1 回答 1

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>

我希望这对可能陷入同样情况的其他人有所帮助。谢谢你。

于 2013-11-25T21:50:36.633 回答