Dynamic Data Binding

PROBLEM

I want my test to dynamically bind to a different data set at run-time. The data I want the test to use will depend on certain conditions of my application, but the test steps will always be the same.

SOLUTION 1

First, be aware that dynamically binding data is not currently a built-in feature in Test Studio. You can only bind a test to a single data source. However, there is a trick you can implement in code to achieve the same result. The trick relies on swapping the data file to which a test is bound at run time. 

  1. Start with a master test. This test may be data bound, but it's not required.
  2. Use some criteria and your code to decide which data file you want to use during that test run.
  3. Swap the physical file on disk with the real file you want to use in your data bound test.
  4. Have your master test call a sub-test that is bound to this data file.

 

For example:

  1. Create a sub-test and bind it to an Excel spreadsheet named Book1.xlsx.
  2. In a coded step in your main test, swap Book1.xlsx for the file you actually want to be used by your sub-test.
  3. Keep in mind that when Test Studio binds a test to an Excel file, it actually makes a copy of the file in the Project\Data folder. Ensure you swap the file located in the Project\Data folder, and not the file in its original location.

SOLUTION 2

Put your data into a SQL data base and Use T-SQL to Pull the Data you want from the database. Optionally, you can Generate a Random Number in your T-SQL to point to the row of data to pull.

SOLUTION 3

You can Create Your Own Test Extension DLL and implement the OnInitializeDataSource in which you can do pretty much anything in code. Place the DLL into the following directory:

  • C:\Program Files (x86)\Telerik\Test Studio\Bin\Plugins\

 

It will be called for every test you execute. Whatever OnInitializeDataSource creates and returns will be used as the data source, overriding any file to which the test may have been previously bound.