简体   繁体   中英

Unable to execute only one Group within TestNG test suite

I'm currently working with WebDriver, TestNG, and Maven to run a small test framework. In this framework, I want to pass a suite of tests and occasionally, if not all tests need to be ran, want to run only a specific test(s) from the groups of tests listed in the test suite.

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

However, when I run the above line with a test suite with more than one test, it will execute all tests with the suite. Stranger yet, if I were to call the second group in the test suite, it will skip the first test as expected to execute the second but will execute the remaining tests as well. POM and example Test Suite below.

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

<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>

So as I stated in my comment above, I decided to give this more thought today and figured I would fiddle with individual dependencies that directly effect my test calls. After trying acouple of different versions of jUnit and not getting any where, I decided to revert back to an older version of TestNG which I used in an older project sometime ago.

Changing to :

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.0.1</version>
    <scope>compile</scope>
</dependency>

This allows for the user to input the following maven statement to execute only the called for test group

mvn clean install -Dsuite=<Smoke> -Dgroups=<testgroup1> -Denv=<thisisanEnvironment> -Dusr=<username> -Dpwd=<password>

I hope this helps anyone else that may have fallen into the same situation. Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM