Common Global Functions

PROBLEM

How can I create common global functions for all my tests? Does Test Studio support global project variables or a built-in data store that can be used for all tests? Is there an ability to collaborate between tests, pass arguments to them, and run a set of tests without using test lists?

SOLUTION

We like to use the term "Test Modularization." Test Studio supports this and we very much encourage implementing it. There are two main methods of accomplishing modularization: Test as Step and Using Code.

Test as Step

Test as Step is the method most commonly used. You write a sub-test to be called by a parent test. The "Login" sub-test is perhaps the most common. We do not limit how deep you can go with sub-tests, although it becomes unmanageable if you go too deep.

 

It is also common to create sub-folders within the test project folder to better organize and group the main tests and sub-tests together. Create a folder on Project tab in Test Studio by right clicking the project node and selecting Create Folder.

Using Code

In this approach you use the Script Step feature to call your own coded functions. These coded functions can exist in one of three places:

 

  1. Within the same code file that test is using (each test may have one code file associated with it).
  2. Within your own code file. Any code file that is placed in the project folder will automatically be included in the compile process. Thus any coded step can refer to the class (or classes) defined with this file. You can even have multiple code files of your own creation. However, you must write them using some tool outside of Test Studio, like Notepad, Visual Studio, etc.
  3. Within a third party .dll. You can Add an Assembly Reference to an external .dll, either created by you or from a third party vendor, then call the functions contained in that .dll from the coded step.

 

The closest built-in feature we have for globally accessible data is Data Driven Testing. Set the sub-test to Inherit the Data from the parent test. This parameterizes the sub-test by binding the parent test to a different set of data.

 

The next best solution is to implement it in code. Define your global variables in code and use them in code. You also have the option of Getting and Setting the Value of a Variable in code such that a non-coded test step can use it like a data bound setting.