How to perform data parameterization in TestNG?

We can perform data parameterization in TestNG. The parameterization in execution in TestNG can be done in the following ways −

  • data parameterization with @Parameters annotation.

  • data parameterization with @DataProvider annotation.


Code Implementation of TestNG xml file with @Parameter annotation.

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "" >
<suite name = "Tutorialspoint Test">
   <parameter name = "Url" value=""/>
   <test name = "Regression Cycle 1">
         <class name = "TestParameter" />

We can pass values at runtime to the test methods by defining <parameter> in the TestNG xml file.


import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestParameter {
   public void loginwithUrl(String urlname) {
      System.out.println("The value of url is : " + urlname);}

Java class files have @Parameters with (“Url”).

Code Implementation with @DataProvider annotation.

@DataProvider(name = "QuestionSearch")
public Object[][] quest_anssearch(){
   return new Object[][]
      { “Tutorialspoint”, “Java”},
      { “Python”, “PyCharm”},
@Test(dataProvider = "QuestionSearch ")
public void userInput(String subject, String lang){
   System.out.println("The values are : " + subject +”“+ lang);

We can pass multiple data at runtime with the help of @DataProvider in the Java class file.