Hello Folks,
In last post, we have seen Why do we need to use DataProvider in TestNG. Now we will see a serie of posts on DataProvider.
Let’s see some examples here which will help you in understanding basic of DataProvider.
package DataProvider;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class DataProviderBasics1 {
// You must need to mention data provider method name in Test method
@Test(dataProvider="DataContainer")
public void methodWithSingleAttribute(String a) {
System.out.println(a);
}
// A data provider which will provide single value to a test method thrice.
@DataProvider(name="DataContainer")
public Object[] myDataProvider() {
// Passing 3 set of data and each set contains single value
Object data[]= new Object[3];
data[0]= "Make";
data[1]= "Selenium";
data[2]= "Easy";
return data;
}
}
Output:
[RemoteTestNG] detected TestNG version 6.14.2
Make
Selenium
Easy
PASSED: methodWithSingleAttribute("Make")
PASSED: methodWithSingleAttribute("Selenium")
PASSED: methodWithSingleAttribute("Easy")
===============================================
Default test
Tests run: 3, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
More about TestNG in upcoming posts. Stay tuned.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning
This programming interview question was asked in Yodlee. Problem: Write a Java program to find and print all special characters…
Hello Folks, TestNG provides a beautiful functionality to parameterized our configuration and test methods so that we can execute the…
Hello Folks, As part of our API Testing series, we will see "Difference between REST and RESTFul API" in this…
Hello Folks, As part of our API Testing series, we will see below topics in this post: What is REST? Six…
Hello Folks, As part of our API Testing series, we will see some important HTTP status codes in this post.…
Hello Folks, Most of us know that, we can pass parameter as a String to methods in TestNG class. Is…