Maven integration in testng

Maven has a very good support for TestNG framework. Maven commands to execute TestNG tests
  • To run all testNG tests, you can use – mvn test
  • To execute tests from specific groups, you can use – mvn test -Dgroups=”sanity,smoke”
  • To execute tests apart from specific groups, you can use – test -Dgroups=!”reg”
  • To execute tests from specific test class, you can use – test -Dtest=BankTest
  • To execute specific test method from specific test class, you can use – test -Dtest=BankTest#test2
Surefire plugin configuration to execute TestNG tests Surefire plugin provides lot of configuration options as mentioned below.
  • We can use suiteXmlFile tag to specify the xml file containing tests to be run.
  • We can use groups tag to specify the names of groups that we want to run.
  • excludedGroups tag can be used to skip tests belonging to specific groups.
  • We can use parallel tag to specify the type of parallelism. Possible values are methods, classes etc.
  • We can use excludes tag to exclude specific test classes from running.
Here is the sample suite.xml file.
 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Component Tests" verbose="2" annotations="JDK">
    <test name="a-t1" preserve-order="true" >
        <classes>
            <class name="org.softpost.AppTest" />
        </classes>
    </test>
</suite>

Here is the sample surefire plugin block.
 
<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <suiteXmlFiles>
        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
      </suiteXmlFiles>
      <excludedGroups>reg</excludedGroups>
      <groups>sanity,abc</groups>
      <parallel>methods</parallel>
      <threadCount>10</threadCount>
      <excludes>
        <exclude>org.softpost.AppTest</exclude>
      </excludes>

    </configuration>
  </plugin>
</plugins>
</build>                    

Web development and Automation testing

solutions delivered!!