TestNG Parametrization: Part-1

Parametrization means passing values in Unit test script using TestNG xml file, or using @DataProvider testing annotation

Parametrization using testing xml file:

For this type of parametrization need to declare “@Parameters” annotation in method which needs parameter testing, the value of parameter will be provided by using TestNG suite xml file. Using this we can Test a single unit test for multiple set of values.
Example – we need to create java test file as I created MyTestNG.java file.

package com.test;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class MyTestNG {       
        public void beforeClass() {
            System.out.println("@BeforeClass - executed");
        public void afterClass() {
            System.out.println("@AfterClass - executed");
        @Parameters({"fName", "lName"})
        public void testParameterMethod(String fName, String lName) 

Suite.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<suite name="TestNG Suite">
  <test name="method">
    <parameter name="fName" value="First Name"/>
    <parameter name="lName" value="Last Name"/>
       <class name="com.test.FirstTest" />     

@BeforeClass - executed
First Name
Last Name
@AfterClass - executed

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution