TestOptimal Wiki

Model-Based Testing (MBT)

User Tools

Site Tools


DataSet Tag

Dataset tag defines a data set which stores rows of data to be retrieved later by mscript function $getData('dsID','fieldName').

Before the dataset can be used, it must be declared and populated data from a data source.

Example model: Example_DataSet

Declare DataSet

The syntax to declare a dataset is:

  <dataset id="datasetid" db="dbid" mode="replace/append" autorewind="true/false"/>

autorewind attribute is used to automatically start at the first row when all rows have been retrieved.

The mode attribute is used to append the new data to the data set or to clear the old data and replace them with the new data.

Although dataset tag may be placed any mscript triggers, it is most often placed in MbT_Trigger which is executed at the beginning of the model execution and it is executed only once per model execution.

If dataset tag is executed multiple times, the recent execution overrides the previous.

Once dataset is declared you can populate dataset with the data from external data sources.

Load DataSet

There are three ways to populate the data set with rows of data.

  • sql - use sql tag to declare the sql statement to be used to retrieve the data from jdbc data source to populate this data set. sql tag must be nested within dataset tag.
  • rowdata tag - use rowdata tag to explicitly populate one row of data into this data set. rowdata tag must be nested within dataset tag. Add one rowdata tag to add one row of data.
  • other sources - you may populate dataset from other sources including csv file, tsv (tab separated) file and Excel workbootk/sheets, url or custom java code.

Before you can use dataset, you must call by calling mscript function $loadFromDataSource('dsID','param1',...).

When you first loaded the dataset, it's positioned at first row (row 0).

Call mscript function $getData('dsID','fieldName') to retrieve a specific field at the current row of the dataset.

Call mscript function $nextDataSetRow('dsID') to advance move dataset to the next row.

Retrieve Data Field

Once the dataset is positioned at the desired index, you can call out each field on the current row using MScript function $getData (…), for example:

$getData ('myDS','F1') or
$getData ('myDS:F1')

Just like other MScript functions, you may nest call like:

$getData ('$getData ('myDS:F1')_x','F22')

In the above example, the inner $getData ('myDS:F1') retrieves the value of column F1 from dataset myDS. The value returned is then concatenated with _x to form the dataset name for the outer $getData (…).

You may retrieve data using a short hand format [dsName:colName] just like calling out system and user variables:


Obviously your dataset name must not contain semi-colon “:” in order to use this short hand syntax.

datasettag.txt · Last modified: 2016/09/22 02:35 (external edit)