Thursday, April 25, 2013

Surefire maven plugging configuration for testng

The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. once you write the test classes under test directory you can use following surefire configurations in pom.xml to run you test classes while building the source.


If you want to run all test classes which name end with TestCase


<build>  
     <plugins>  
       <plugin>  
         <artifactId>maven-surefire-plugin</artifactId>  
         <version>2.12.3</version>  
         <inherited>false</inherited>  
         <configuration>  
           <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=128m</argLine>  
           <testFailureIgnore>true</testFailureIgnore>  
           <disableXmlReport>false</disableXmlReport>  
           <parallel>false</parallel>  
           <includes>  
             <include>**/*TestCase.java</include>  
           </includes>  
         </configuration>  
       </plugin>  
     </plugins>  
   </build>  

Other option is that you can create a test suite by defining test classes or test packages in a xml file called testng.xml


<build>  
     <plugins>  
       <plugin>  
         <artifactId>maven-surefire-plugin</artifactId>  
         <version>2.12.3</version>  
         <inherited>false</inherited>  
         <configuration>  
           <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=128m</argLine>  
           <testFailureIgnore>true</testFailureIgnore>  
           <disableXmlReport>false</disableXmlReport>  
           <parallel>false</parallel>  
           <suiteXmlFiles>  
             <suiteXmlFile>src/test/resources/testng1.xml</suiteXmlFile>  
           </suiteXmlFiles>  
         </configuration>  
       </plugin>  
     </plugins>  
   </build>  

your testng.xml file should be defined as bellow. you can defined your test classes or or package to be run

<suite name="MyTestSuite" parallel="false">   
   <test name="Test1" preserve-order="true" verbose="2">   
    <classes>   
     <class name="com.test.MyTestClass1"/>  
     <class name="com.test.MyTestClass2"/>   
    </classes>   
   </test>   
  <test name="Test2" preserve-order="true" verbose="2">   
    <packages>   
     <package name="com.test.*"/>   
    </packages>   
   </test>   
  </suite>

No comments:

Post a Comment