Data binding is an important feature in Visual Studio web testing. It allows you to test a web app against random, sequential, or unique iterations of a set of test data. This allows more complete and comprehensive tests as opposed to running the same static test data through the web app on every single iteration of the test.
When running a load test, it may not be suitable to use a remote data source for data binding, especially if the data you need is in a database that gets accessed by the web app you are testing. This is where a local data source may work best, such as CSV file, MS Access, or MS Excel spreadsheet files.
I found it not intuitive at all to setup data binding to an Excel spreadsheet, so I thought I would share what I found from a couple sites. Mainly, this page.
Adding a CSV Data Source
Follow these steps to add a CSV file as a data source
1.) Create a directory to hold your CSV file
2.) Place your CSV file in the directory and make sure the file has a header row
3.) In the Web Test Editor click the Add Data Source button on the toolbar.
4.) Select “Microsoft Jet 4.0 OLE DB Provider” from the OLE DB Provider drop down.
5.) In the server or file name text box, enter the directory that the CSV file exists in. Do not enter the file name; just enter the directory where the file is located.
6) Click the advanced button.
7.) Click on Extended Properties.
8.) Set the value equal to: text
9.) Click Ok to close the advanced editor.
10.) Click Ok to close the connection property dialog.
11.) Click the check box for the files with the data you would like to use for this test case then click Ok.
12.) Now the text file is ready to use a data source.
Adding an Access Database as a Data Source
After setting up the database, perform the following steps to add the data source.
1.) In the Web Test Editor click the Add Data Source button on the toolbar.
2.) Select “Microsoft Jet 4.0 OLE DB Provider” from the OLE DB Provider drop down.
3.) In the server or file name text box, enter the directory and file name of the access database. i.e. c:\temp\databinding.mdb
4.) Click Ok to close the connection property dialog.
5.) Choose the tables you would like to include for data binding then click Ok. Now the access database is ready to use a data source.
Adding a SQL Server Database as a Data Source
After setting up the database, perform the following steps to add the data source.
1.) In the Web Test Editor click the Add Data Source button on the toolbar.
2.) Select “Microsoft OLE DB Provider for SQL Server” from the OLE DB Provider drop down.
3.) In the server or file name text box, enter the database server
4.) Enter the username and password or select the “Use Windows NT Integrated Security” option.
5.) If you entered a username and password check the “Allow saving password” checkbox.
6.) Choose the database name from the dropdown list.
7.) Click Ok to close the editor.
8.) Choose the tables you would like to include for data binding then click Ok. Now the SQL Server database is ready to use a data source.
Adding an Excel Spreadsheet as a Data Source
One excel worksheet can define multiple tables that can be used for data binding. In order to use an Excel spread sheet as a data source, you need to do the following.
1.) Create an excel worksheet.
2.) The first row of your table should be column headers. You can have multiple tables on one work sheet or spread the tables across multiple worksheets. The following steps need to be done for each table which will be used.
3.) Highlight the entire table including the column headers.
4.) On the insert menu point to name and then click define.
5.) Type a name for this selection and click Ok.
6.) This process needs to be done for each table in the workbook that will be used for data binding.
7.) When you are done save the workbook and exit excel.
Note: If you add more rows to a table after you define it, you will need to update the definition by doing this process again. Otherwise the new data will not be available for testing.
The next step is to add the data source to the test case. Follow these steps for that process
1.) In the Web Test Editor click the Add Data Source button on the toolbar.
2.) Select “Microsoft Jet 4.0 OLE DB Provider” from the OLE DB Provider drop down.
3.) In the server or file name text box, enter the directory and file name of the excel spreadsheet. i.e. c:\temp\book1.xls
4.) Click the advanced button.
5.) Click on Extended Properties.
6.) Set the value equal to: Excel 8.0
7.) Click Ok to close the advanced editor.
8.) Click Ok to close the connection property dialog.
9.) Choose the tables you would like to include for data binding then click Ok. Note: The worksheet names appear in this list with a $ after them. You can use these for table data. If you try to use these, the test will hang. You need to select the name you gave the table in your worksheet.
10.) Now the excel file is ready to use a data source.
Additional Considerations when adding a Data Source
If you are going to be executing a web test on a Controller/Agent setup, you need to consider the location of the data source before creating the connection string. The data for a data source is loaded on each agent machine. So if you create a data source and set the location to c:\test\datadinding.mdb because this is were it is located on the client machine, the agent will also expect the MDB file to be located in the same location on the agent machine. There are 2 options for handling this problem:
1.) Place your data sources on a network share that each agent can access. So when you create the data source, you would use some like \\machine\datasources\datadinding.mdb. Since each agent has access to this location, the connection string will work for each agent.
2.) The other option is to copy the data source to the same location on each agent machine. So if you create your connection string with c:\test\databinding.mdb, then you would need to create a c:\test directory on each agent and copy the databinding.mdb file to the directory.