Test variables
A test variable is a user-defined, name-value pair that stores and refers to information throughout a test and between tests.
- Provide a default value to the variable during declaration.
- Change the value of the variable using Set Variable statement. You can use the Add and Insert menus of the Test Editor to create Set Variable statements.
- Set hard-coded value or value retried from a data source, such as dataset or reference that appears before the Set statement to the variable.
- Compound test setting in the variable table UI
- Compound test specified in a var file
- User group setting in the variable table UI
- User group specified in a var file
- Schedule specified setting in the variable table UI
- Schedule specified in a var file
- Command line
Sharing variables among tests
In order to share variables between tests, all the tests must contain the variables with the same name. The variables must also have Visible in set to All tests for this user. When these conditions are met and multiple tests have been placed in a schedule, then variable in the dataset of one test can be used in the other test.
A common reason to share data between tests is to perform data correlation. With data correlation, a variable is set to a response that comes from a request in one test and is used in requests performed in a different test. Assume that you are testing an employee database. The Create Employee test creates an employee record and the Modify Employee test modifies an employee record. When a new record is created, it is assigned a record ID. Variables can be used to pass the record ID from a response in the Create Employee test to the Modify Employee test. A user-defined variable is not shared among different virtual users. The variable is shared only among the different tests of the same virtual user. If you set Visible in to This test only, then dataset from a test is not available to another even if both tests contain variables with the same name.
- Declare the test variables with the same name across all the test scripts for the variables to communicate with each other. Set Visible in to All tests for this user.
- Include the required test scripts into a compound test.
Using test steps, you can share the default values of the variables to another test script. You can also assign new values to the variables and use the latest values in another test script.
If you want to share variables between the test scripts of different testing products such as Rational® Functional Tester, Rational® Performance Tester, or Rational® Integration Tester, you must consider the following points:
- If you are using Installation Manager, you must shell-share or install the products in the same package group.
- Declare the test variables with the same name across the Rational® Functional Tester and Rational® Performance Tester test scripts. Set Visible in to All tests for this user.
- Include the required test scripts into a compound test.
- If you are using Rational® Integration Tester test scripts, you must map your tags with the test variables of Rational® Functional Tester or Rational® Performance Tester.
Using variables to access datasets
You can define variables so that they share data from a dataset throughout tests. This is achieved by having the value field of a Set Variable statement substituted from a dataset. By doing so, the first test which appears in the schedule can set the variable from a dataset and share it with the other test in a schedule.
Assume that you have two tests that log in to an application using a user ID from a dataset. The first test can set the value of a variable from the dataset, and both tests can use the variable, instead of directly using the dataset. In this case both use the same record from the dataset. This is similar to the fetch-only-once-per-user behavior of a dataset. However, fetching once means that during playback, a virtual user gets only one record from the dataset. The one-record limit holds even if the tests are in a loop, and are run several times by the virtual user. By using the user-defined variables, the virtual user retrieves a new record each time through the loop, and both tests can use the same record.
Array variables
You create an array variable to add multiple values to a variable. If you create a secondary HTTP request, add complete paths of the requests in the array variable that can be used a custom code during playback.