What is parameterization in TestNG? How to pass parameters using testng.xml?

Parameterization is the technique of defining values in testng.xml file and sending them as parameters to the test class. This technique is especially useful when we need to pass multiple login credentials of various test environments. Take a look at the code below, in which “userName” is annotated as a parameter.

public class ParameterizedTest1
{
    @Test
    @Parameters("userName")
    public void parameterTest(String userName)
    {
        System.out.println("Parameterized value is : " + userName);
    }
}

To pass parameters using testng.xml file, we need to use "parameters" tag. Look at the below code for example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd">http://testng.org/testng-1.0.dtd</a>" >
<suite name=”CustomSuite">
    <test name=”CustomTest”>
        <parameter name="userName" value=”Rohan"/>
        <classes>
            <class name="ParameterizedTest1" />
        </classes> 
    </test>
</suite>