Archive for the ‘Unit/Load Testing’ Category

Visual Studio 2005 Web Test Data Binding

Wednesday, April 18th, 2007

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.

Visual Studio 2005 Team Suite Unit Testing Note

Thursday, April 12th, 2007

In case anyone else is having this problem and cannot find a solution:

I just created a new unit testing project with Visual Studio, using C#. The skeleton program it creates looks simple enough. The skeleton code that was generated for me has these 4 namespace includes:
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Without changing anything in the code or project, I attempted to build it, I got these errors:
error CS0234: The type or namespace name ‘VisualStudio’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)
error CS0246: The type or namespace name ‘TestMethod’ could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name ‘TestClass’ could not be found (are you missing a using directive or an assembly reference?)

This is weird since a skeleton project should just build. I searched online for these errors and found NO ONE posting the same problem. Hoping to just simply be able to add a reference to the project, I looked for any DLL files on my system named “Microsoft.VisualStudio.TestTools.UnitTesting.dll” or similar and found nothing. I looked in the built-in list of .Net namespaces and could not find it either.

Solution:
Searching for less similar named references, I happened to stumble upon the correct reference. It is a built-in .Net namespace reference, just not named “Microsoft.VisualStudio.TestTools.UnitTesting”, but rather: “Microsoft.VisualStudio.QualityTools.UnitTestFramework”. To add this to your unit test project, go to “Add Reference” and it should be listed under the .Net tab in the mix of other namespaces. When I added this to the references, the code compiled just fine, without modifying the namespace includes or anything.

As far as I know, unit testing is only available in Visual Studio 2005 Team Suite edition, but I have read it is also in Visual Studio 2005 for Team Testers edition.