In the past, we've had several PMRs on how to share a variable in one service test and have that variable used in another service test in Performance Tester. It's rather easy to do but not obvious. This article will show you how it's done.
Let's start with two simple tests: Add1Plus1 and Add1Plus2. These tests are based on the calculator example shipped with Rational Test Control Panel.
As expected, the result of the Add1Plus1 test will be ‘2’.
The result of the Add1Plus2 test will be ‘3’
Now, let's say, we want the Add1Plus2 test to not add 1 plus 2, but add the result of the Add1Plus1 test and 2. Here are the steps.
1- Create a schedule
The first requirement for one test to pass a value to another test is that the two tests must be on the same schedule. Here’s a simple schedule that contains these two tests.
In addition, we need to change the logging of the schedule to ALL/ALL/ALL. Otherwise, we won't see the actual requests and response details.
After rerunning the schedule, we can now see the details of the actual request and the results.
2 - Create a global variable
The next step is to declare a variable. In the Variable Details section, set Visible in: field to All tests for this user. This makes the variable global.
Once you have defined, simply copy this variable and paste it into the second test, Add1Plus2. In this test, the variable is initialized to ‘1’ allowing the test to run standalone or on a schedule with the Add1Plus1 test. It won't try to add a null value if Add1Plus1 test wasn't run and didn't set the initial value.
3 - Assign the result of 1 plus 1 to the global variable
This part is a bit tricky. In the test, click Insert then Variable Assignment. Choose the ResultOf1Plus1 variable.
Choose the ResultOf1Plus1 variable.
Then, choose a Datasource value: for the Set to value.
In the dialog box that pops up, select "2".
Save the test.
4 - Assign the value of Value1 in the Add1Plus2 test to the global variable
This is straightforward. Find the "1" in Value1 and right-click and do Substitute and then Select Data Source.
Choose the global variable, ResultOf1Plus1.
The "1" is now in purple color, which means it's substituted at run time.
Save the test.
5 - Run the schedule
When we look at the test log of running the AddSchedule, we see Add ("3") for the result in the Events of the test log but the Raw Transaction Data shows "4" as the result. This is confusing and misleading.
"4" is the actual correct result; it's the result of add 1 plus 1 which is 2, and 2 which is 4.
The node of the request will be displayed in the Events of the test log, and not the actual values being added. To make this more meaningful, go to the Request Settings of the Add("1", "2") and change it as shown in this example.
Now, the Events in the test log will appear as shown below.
Similarly, the node name for Add ("3") can be changed to something more meaningful. Rely on the Raw Transaction Data of the test and not node names in the Events to see what's being sent and received.
Sharing a variable across tests is rather straightforward. Even though this example used service tests, the same technique can be used to share a variable across HTTP tests.
Paul Liskay is a Level 2 support engineer for the Testing Tools for the US geography, focusing primarily on Performance Tester, Integration Tester, and Web UI Tester. Prior to joining the support team, he was the team lead for the Integration Tester 8.0 release, and a team lead for Performance Tester for the 8.0 through 8.2 releases. He was also on the system test team for Rational Team Concert for the 4.0 release.