Testng Online Tutorials

TestNG is a testing framework for the Java programming language created by Cedric_Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities.

TestNG
Developer(s)Cédric Beust, the TestNG team
Stable release
7.6.1 / July 4, 2022; 2 years ago (2022-07-04)
Repository
  • github.com/cbeust/testng Edit this at Wikidata
Written inJava
Operating systemCross-platform
TypeUnit testing tool
LicenseApache License 2.0
Websitetestng.org

Features

edit

TestNG's main features include:


Data provider

edit

A data provider in TestNG is a method in a test class, which provides an array of varied actual values to dependent test methods.

Example:

	//This method will provide data to any test method that declares that its Data Provider is named "provider1". 
	@DataProvider(name = "provider1")
	public Object createData1() {
		return new Object { 
			{ "Cedric", new Integer(36) },
			{ "Anne", new Integer(37) }
		};
	}

	// This test method declares that its data should be supplied by the Data Provider named "provider1".
	@Test(dataProvider = "provider1")
	public void verifyData1(String n1, Integer n2) {
		System.out.println(n1 + " " + n2);
	}

	// A data provider which returns an iterator of parameter arrays.
	@DataProvider(name = "provider2")
	public Iterator<Object> createData() {
		return new MyIterator(...);
	}	

	// A data provider with an argument of the type java.lang.reflect.Method.
	// It is particularly useful when several test methods use the same 
	// provider and you want it to return different values depending on 
	// which test method it is serving. 
	@DataProvider(name = "provider3")
	public Object[] createData(Method m) {
		System.out.println(m.getName()); 
		return new Object[][] { new Object[] { "Cedric" } };
	}

The returned type of a data provider can be one of the following two types:

  • An array of array of objects (Object[][]) where the first dimension's size is the number of times the test method will be invoked and the second dimension size contains an array of objects that must be compatible with the parameter types of the test method.
  • An Iterator<Object[]>. The only difference with Object[][] is that an Iterator lets you create your test data lazily. TestNG will invoke the iterator and then the test method with the parameters returned by this iterator one by one. This is particularly useful if you have a lot of parameter sets to pass to the method and you don't want to create all of them upfront.

Tool support

edit

TestNG is supported, out-of-the-box or via plug-ins, by each of the three major Java IDEs - Eclipse, IntelliJ IDEA, and NetBeans. It also comes with a custom task for Apache Ant and is supported by the Maven build system. The Hudson continuous integration server has built-in support for TestNG and is able to track and chart test results over time. Most Java code coverage tools, such as Cobertura, work seamlessly with TestNG.

Note: TestNG support for Eclipse is on

Testng Tutorials: TestNG is a testing framework focused on providing both unit and functional testing abilities in the Java programming language. It supports parallel testing, data providers, dependencies, groups and other features.

Latest online Testng Tutorials with example so this page for both freshers and experienced candidate who want to get job in Testng company

Latest online Testng Tutorials for both freshers and experienced

advertisements

View Tutorials on Testng View all questions

Ask your interview questions on Testng

Write Your comment or Questions if you want the answers on Testng from Testng Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---