Read it out for TESTNG before going for an iterview


How to run a group of test cases using TestNG?
TestNG allows you to perform sophisticated groupings of test methods. Not only can you declare that methods belong to groups, but you can also specify groups that contain other groups. Then TestNG can be invoked and asked to include a certain set of groups (or regular expressions) while excluding another set.  This gives you maximum flexibility in how you partition your tests and doesn’t require you to recompile anything if you want to run two different sets of tests back to back.
Groups are specified in your testng.xml file and can be found either under the <test> or <suite> tag. Groups specified in the <suite> tag apply to all the <test> tags underneath.
@Test (groups = { "smokeTest", "functionalTest" })
public void loginTest(){
System.out.println("Logged in successfully");
}
 How to create Group of Groups in TestNG?
Groups can also include other groups. These groups are called MetaGroups. For example, you might want to define a group all that includes smokeTest and functionalTest. Let’s modify our testng.xml file as follows:
<groups>
   <define name="all">
                 <include name="smokeTest"/>
                 <include name="functionalTest"/>
   </define>
   <run>
         <include name="all" />
   </run>       
</groups>
How to run test cases in parallel using TestNG?
we can use “parallel” attribute in testng.xml to accomplish parallel test execution in TestNG
The parallel attribute of suite tag can accept four values:
tests – All the test cases inside <test> tag of testng.xml file will run parallel
classes – All the test cases inside a java class will run parallel
methods – All the methods with @Test annotation will execute parallelinstance – Test cases in same instance will execute parallel but two methods of two different instances will run in different thread.
<suite name="softwaretestingmaterial" parallel="methods">
How to exclude a particular test method from a test case execution? 
By adding the exclude tag in the testng.xml
<classes>
  <class name="TestCaseName">
     <methods>
       <exclude name="TestMethodNameToExclude"/>
     </methods>
  </class>     
</classes>
How to exclude a particular test group from a test case execution? 
By adding the exclude tag in the testng.xml
<groups>
    <run>
                 <exclude name="TestGroupNameToExclude"/>
    </run>     
</groups>
 How to disable a test case in TestNG ?
To disable the test case we use the parameter enabled = false to the @Test annotation.
@Test(enabled = false)
How to skip a @Test method from execution in TestNG?
By using throw new SkipException()
Once SkipException() thrown, remaining part of that test method will not be executed and control will goes directly to next test method execution.
throw new SkipException("Skipping - This is not ready for testing ");
 How to Ignore a test case in TestNG?
To ignore the test case we use the parameter enabled = false to the @Test annotation.
@Test(enabled = false)
How to write regular expression In testng.xml file to search @Test methods containing “smoke” keyword.

Regular expression to find @Test methods containing keyword “smoke” is as mentioned below.
<methods>
     <include name=".*smoke.*"/>
</methods>


Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  3. Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.

    Data Science course in kalyan nagar | Data Science course in OMR
    Data Science course in chennai | Data science course in velachery
    Data science course in jaya nagar | Data science training in tambaram

    ReplyDelete
  4. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    java training in jayanagar | java training in electronic city

    java training in chennai | java training in USA

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

Handling Dynamic Web Tables Using Selenium WebDriver

Verify Specific Position of an Element