Functionality to get total number of rows from dataset

book

Article ID: 222153

calendar_today

Updated On:

Products

CA Application Test

Issue/Introduction

How to get the total number of rows from dataset file (CSV file) without iterating rows?

Cause

None

Environment

Release : 10.6

Component : Service Virtualization

Resolution

As is DevTest doesn't provide the functionality to get the total count of rows from CSV/Excel file when it is used in a Test case or in a VSM. To get the row count of CSV/Excel file can add the below Beanshell code in a scripted assertion in a Test step where dataset is defined or after that step and it should work.

--------
import org.apache.commons.io.FileUtils; 
int lines = FileUtils.readLines(new File("{{LISA_RELATIVE_PROJ_ROOT}}/Data/CountDataset.csv")).size(); 
testExec.setStateValue("DTSCnt", lines);
return true;
---------------
 
In the above code DTSCnt property will give the row count.