Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Transient Test Suite Variables

Options
LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
Creating, Using, and Saving
Hi Everyone,

A lot of this information can also be found in the Scripting API accessible via the Help Menu. The examples here involve variables that will be reset to the initial value of your choosing after each test run.


These are available as far back as 4.5.1 SP2.0, although the GUI has changed a bit. In 5.0.1, you can create Test Suite Variables in the following manner:
  • Click on the Test Suite Folder in which the variable will be stored.
  • Go to the Executions Options tab.
  • Go to the Test Variables tab.
  • Click Add. A new Test Suite Variable appears.
  • Double-click on the Name or Value. A dialog appears in which you can set both Name and Value. The default value is 0 for an integer and false for a boolean. String variables are scheduled for inclusion in future versions.
Now that you have a Test Suite Variable, this code will allow you to access it (assuming you have named the variable "myVar"):
CODE
#myVarTSV is a member of the TestSuiteVariable class
myVarTSV = context.getVariable("myVar")


Once you have accessed a Test Suite Variable, you can manipulate it with getValue() and setValue(). Note that this example is not strictly good coding practice but is intended to demonstrate what is happening.
CODEincrementAndSet(myVarTSV):
   #getValue() always returns a string
   myVar = myVarTSV.getValue()

   #Cast to int
   myVarint = int(myVar)

   #Increment by one
   myVarint += 1

   #Cast to str
   myVar = str(myVarint)

   #Store myVar to use later in the test run
   myVarTSV.setValue(myVar)


Now, when the next test runs, myVar will have the incremented value, but the next time you run your tests, it will start with the value determined in the Test Suite Execution Options.
Tagged: