01 March 2010 - 3.5 |
The "DataGen" TestStep can be used to generate data to be used as input in your TestCases, Requests, etc, 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. Create a DataGen Step as usual from the TestCase popup menu. Double-clicking the TestStep will open the following editor:
The table at the top contains the defined DataGen properties with their common settings (see below) and last returned value, selecting a property in the table shows the corresponding configuration panel at the bottom.
"Running" the DataGen step with the far left toolbar button will re-evaluate all properties and show their values in the far right table column.
Add and delete properties using the toolbar buttons at the top, the Add button opens the following dialog:
The types of property available are currently:
The configuration panel when selecting a Script property is as follows:
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 todays date when used.
The Template configuration-panel is equally simple:
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 property-expansions, for example
<date><today>${DataGen#today}</today></date>
Which would evaluate to an XML element containing todays date when used in conjunction with the above defined script-property.
This property type is used for generating lists of numbers; the start/end/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 will save the last number when saving the project so the sequence can continue at its last value if required, remember to use the -S option when running through the command-line tools to save the project after running the tests. At the bottom the next value that will be returned by this property is displayed and an option to set this to a specific value is available (these will be disabled if the number is configured to be random).
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:
Another straight-forward configuration:
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.
The table listing the properties contains two more configuration possibilities; Mode and Shared.
Mode controls how the property value is evaluated 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/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. Please note that before this execution the property will not have any value at all so be sure to put the DataGen before any steps that might be referring to it.
Shared controls whether the property should be shared between threads in a LoadTest; 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.