DataGen TestStep

NOTE: This page contains information about the DataGen test step that is included in ReadyAPI.
To try the described functionality, feel free to download a ReadyAPI trial.

1. DataGen TestStep

The DataGen TestStep can be used to generate data to be used as input in your TestCases, for example number or date sequences, random selections, etc. The generated data is available as properties and can thus be referred to with Property Transfers and Expansions just like any other property. Let us have a quick look at the available possibilities.

Start by creating an empty TestCase and adding a DataGen Step to it, you will see the following editor:

Empty-DataGen

The table at the top will contain the defined DataGen properties with their common settings (more on those later), and selecting a property in the table shows the corresponding configuration panel at the bottom.

Let us start by creating a property; select the Add button in the toolbar which opens the following "Add..." dialog:

add-genereated-property

2. DataGen Types

The types of property available are currently:

  • Script : specifies a property whose value is created by a groovy script
  • Template : specified a block of content to be used when building other values
  • Number : allows for number-based sequential creation of property values (integers, dates, etc)
  • List : specifies a list of possible values to return when the property is read

Let us have a quick look at these in more detail:

2.1. Script

The configuration panel when selecting a Script property is as follows:

DataGen-with-today-property

This is pretty straightforward. Specify a groovy script that returns the desired value for the property. For example, you could create a property that contains today date in a nice format:

def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
return sdf.format( new Date())

Anywhere in your TestCase where PropertyExpansions are available, you could use this with ${DataGen#today}, which would be replaced with today's date when used.

2.2. Template

The Template configuration-panel is equally simple:

DataGen-with-2-properties

This type is useful for building complex multiple-line properties, for example to be inserted into requests. Here one can specify any content that can also contain PropertyExpansions, for example

${DataGen#today}

This would evaluate to an XML element containing today's date when used in conjunction with the above-defined script-property.

2.3. Number

This one is a bit more complex:

datagenNumber

This property type is used for generating lists of numbers. The start, end or step values specify the range of the sequence and its increment or decrement. The pattern specifies how to format the property value using the java DecimalFormat class (see this page for some examples). Selecting the Random check box will select a random number within the specified range instead (with specified step as modulus). The Persist options stores the last number issued upon saving the project. This will allow for the sequence to continue if the previous value required (Note: Projects are not saved after running through the command-line tools).

So for example if you want to generate random USD currencies between 100 and 1000 USD with a 50 USD increment you could specify the following:

datagenNumberExample

2.4. List

Another straightforward configuration:

DataGen-with-weekday-property

The above screen shot configures a list of weekdays and sets the property to select a random line each time it is read, if the Randomize check box is not checked, the values are used sequentially.

3. Common Configuration Properties

The table listing the properties contains two more configuration possibilities, Mode and Shared.

3.1. Mode

Mode controls the evaluation of the property value and has two possible values; READ and STEP. READ will re-evaluate the property each time it is referenced. This works ok with (for example) our today property created above and any other property that can/should have its value recreated every time. This may not always be desired though; for example, you might be using a Number property to generate a unique ID to use during the entire run of a TestCase. If you are referring to this ID in several requests or scripts etc, setting it to READ would give you a new value every time, instead of one value that is always the same. In this case set the Mode to STEP and the property will be evaluated when the DataGen TestStep is executed during the execution of the containing TestCase. Note: Prior to execution the property has no set value. Place the DataGen step before any steps that may be referring it.

3.2. Shared

Shared controls whether the property should be shared between threads in a Load Test; maybe you are using a Number property to create unique sequential IDs and also need them to be unique across threads in which case this property is required to be shared, otherwise each thread would create the same sequence of values which would then not be unique across all runs.