Load Testing in Visual Studio 2010

Have you ever wondered if your custom data access code is any more efficient than simply loading a DataTable? Not that I’d recommend using DataTables except for certain situations, but Visual Studio 2010 Ultimate makes it easy to load test your data access classes to determine performance.

In order to test this out I created a sample solution in VS2010 with a data access project and a unit test project. You can download the full source code here. This code runs against the chinook database found on codeplex (I’ve also included the .sql script in my code). First I started by creating a simple data access class.

load_testing_code_1

I then followed up with a very basic unit test for each method.

load_testing_code_2

After creating the tests and running them to ensure they passed, I was ready to create my load test. To create a load test, right-click on your test project and select New Load Test.

Right-click on your test project and select New Load Test.

You can then follow the wizard to specify properties such as how many users to simulate, how long to run the test, and which unit tests to execute.

New Load Test Wizard

New Load Test Wizard

NOTE: If your unit tests aren’t showing up in the test list, make sure to build your solution.

After clicking Finish the load test will appear as a new item in the test project. Double-clicking it will bring up the load test window:

Double-clicking it will bring up the load test window.

Right-click on the Load Test name (LoadTest1 in this case) and select Run Test to begin the test. You’ll be presented with a window containing graphs and stats that are updated real-time as the test runs to show you things such as processor utilization, test response time, tests run per second, etc.

A window containing graphs and stats that are updated real-time as the test runs to show you things such as processor utilization, test response time, tests run per second, etc.

Once completed you’ll be shown a window with results and you can verify the average duration of each test run and know that using a datareader to load your custom class is about 10% faster than loading a datatable.

Although this example was pretty simple to demonstrate the features of Visual Studio Load Testing, it’s not hard to see how useful this tool can be to determine capacity and performance bottlenecks in your system. For more information take a look at the Tech Ed 2011 Perfomance Testing Session.

author avatar
Adam Miller

Related posts