Why testNG @Test annotation is iterating for 4 times instead of 3 times with dataProvider parameter

Can anybody help me?

Train Asked on December 14, 2014 in Selenium WebDriver.

please give Some More Details..?

on December 14, 2014.

Either provide more details on this question or I will delete this question.

on December 15, 2014.

Dear Sir, Here I am writing all of my code,

This is my Util Class to read data from excel file and returning data

package com.syner.poi;
import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.ss.usermodel.WorkbookFactory;
public class Util {

public static Object[][] readExcelData() throws InvalidFormatException, IOException


Object[][] data=new Object[4][2];

InputStream f=new FileInputStream("GmailTestData.xlsx");

Workbook workbook=WorkbookFactory.create(f);

Sheet sheet=workbook.getSheetAt(0);

int rc=sheet.getLastRowNum();

for(int i=0;i<rc;i++)


Row r=sheet.getRow(i+1);

int cc=r.getLastCellNum();

for(int j=0;j<cc;j++)


Cell c=r.getCell(j);





else if(c.getCellType()==c.CELL_TYPE_NUMERIC)



data[i][j]=new Long((long) c.getNumericCellValue());


System.out.println("Data: "+data[i][j]);

return data;

This is my ExcelFile class to get data from Util class and execute the tesecases.

package com.syner.poi;
import java.io.IOException;

import java.lang.annotation.Retention;

import java.lang.annotation.RetentionPolicy;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;
public class ExcelFile {

WebDriver driver;

public Object[][] readData() throws InvalidFormatException, IOException


return Util.readExcelData();


public void setUp()


driver=new FirefoxDriver();




public void testApp(String firstName,long mobileNumber)





public void tearDown() throws InterruptedException





This is my  GmailTestdata excel file.

Why testNG @Test annotation is iterating for 4 times instead of 3 times with dataProvider parameter

When I execute the above code, it has to execute 3 times because GmailTestdata excel file having 3 recods but it is executing 4 times and for 4th time it is taking (null,null) as arguments.

Thanks & Regards

on December 15, 2014.

Please close the question.

on December 16, 2014.
Add Comment
  • 1 Answer(s)

    Try changing this statement:

    Object[][] data=new Object[3][2];

    Professor Answered on December 15, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.