The blog gives you idea of testing and automation testing example of selenium webdriver,SQl and Jmeter, you see the basic example of selenium web driver and get idea how to do automation testing,

Include and Exclude Java method on TestNG

TestNg provides an options to include or exclude Groups, Java class, Java methods using include and exclude tags in XML file.

Below is the example which give you how to user include and exclude tags for methods.
Let as take an example : if you have a class which contents 5 or 6 java method in which you want to executed only two method and remaining method does not execute know.

I will create a Java class which contents five methods, in which we will include two methods and remaining three would be exclude.

Below is the example class file with three test methods

package testng_Example;
import org.testng.annotations.Test;
public class includeExculde {

  @Test
  public void testingFrist() {
  System.out.println("======= which Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingSecond() {
  System.out.println("======= Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingThird() {
  System.out.println("======= Class is executed and pass for TestNG ======" + Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingFourth() {
  System.out.println("======= Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
  }
  @Test
  public void testingFifth() {
  System.out.println("======= Class is executed and pass for TestNG ======"+ Thread.currentThread().getStackTrace()[1].getMethodName());
  }
}

In the above example, we have created five methods, 'testingFirst','testingSecond','testingThird','testingFourth' and 'testingFifth'

In testng.xml file we will include "testingFirst","testingSecond" and "testingFourth" and exclude "testingThird" & "testingFifth" and try to execute the same using testng.xml and it will execute the Three class and does not execute two classes. Methods always define inside class tag.






After running the above testng.xml file, we will get the output as below. It will just run the test methods which are included in the class. And will not execute the test methods which are in excluded.
======================================================================
[TestNG] Running:
  C:\workspace\Blogger_Example\testng.xml

======= which Class is executed and pass for TestNG ======testingFrist
======= Class is executed and pass for TestNG ======testingSecond
======= Class is executed and pass for TestNG ======testingFourth

===============================================
Suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================


No comments

Post a Comment

Powered by Blogger.