Load Testing ASP.NET Applications with Visual Studio 2010

Quick introduction to the Web Load Test features of Visual Studio 2010

Many developers are not even aware that you can set up and run some very sophisticated web load tests for an ASP.NET Application right from within Visual Studio -- the Ultimate Edition. I don't know if this is because they don't think testing is important, or just because of lack of knowledge.

I think testing is very important, and I've been doing it with .NET since 2001, when I was a lead on a Microsoft - sponsored project to develop banking middleware in what was then a very new .NET Platform. I spent the better part of three weeks at the Microsoft facililty in Charlotte learning all the tricks of the trade from some very smart 'softies. The lessons I learned there have stayed with me ever since. And those lessons are: Test, Test, and Test! Not just unit tests, but load and performance tests as well. Test all your "stuff" thoroughly BEFORE you put it into production!

Testing helps remove that sinking feeling in the stomach when software you've put into production does bad things! Web Load Testing is also useful in production scenarios - for example, say you've decided to switch ASP.NET to WebGarden mode. How do you find the optimal number of processes? You can write a web load test for that and get realtime performance metrics that will enable you to know for sure. Web Load Testing can also be used to measure performance and bottlenecks in WCF RIA Services. You can enlist multiple machines as controllers and multiple machines as agents.

In my book, developers who do not test their software are simply -- not developers.

Let's do a quickie intro into how to set up a web load test project in Visual Studio, Ultimate Edition. I guarantee that this quickie will get you to first base faster than anything else you may have seen. But after that, it's up to you to study some more. All I want to do here is get you to "first base" with the Test platform.

First, we need to set up a load test repository in SQL Server or SQL Express. If you do not have a database named "LoadTest2010", then open up SQL Server Management Studio (SSMS) and use the File/Open/File dialog from the top left of the menu to load the loadtestresultsrepository.sql script from "C:\Program Files (x86)\Microsoft Visual Studio 10\Common7\IDE" (Remove the "(x86)" from the path if you have a 32-bit OS). Execute the script and you are done.

Now in Visual Studio, from the top TEST menu, choose "Manage Test Controllers" and configure your Load Test Results Store to your new database, LoadTest2010.

You are now ready to set up a test.

1) In the same solution as your ASP.NET project, add a new Test project.
2. Right click the TestProject1 node in Solution Explorer, and you will see you have a number of options. Choose "Add", and you'll see you have the choice of a number of different kinds of tests. Choose a "Web Performance Test". You'll notice that Internet Explorer comes up; this is the Web Test Recorder. You can enter the url of the initial page you want to test here. The test recorder will record everything you do: logging in, navigating to other pages, and so on. When you are done, click the "Stop Recording" link. You've now configured a web test. Note that if your project is configured to use the Web Development Server and not IIS, the WebDev server must be running!

3) Now lets add a load Test. Again from the project context menu, choose Add, and this time choose the "Load Test" option. You'll see the following wizard come up:

The wizard has many options that you will probably want to explore and study, but for now, let's just "get to First Base" by clicking through. When you get to the "Test Mix" Wizard page, of course you must add your WebTest1 that you added in step 2. When you've completed the Wizard, you'll now have a complete load test, ready to run!

4) To run your load test, just right- click on it and choose "Run Test". You'll get to see some nice performance graphs in real time, and your ASP.NET Load testing career is now in full swing! Obviously, there is a lot more to study. To find more information, visit the MSDN Forum here. Another great resource is the Performance Testing Quick Reference Guide on codeplex.com.

By Peter Bromberg   Popularity  (15631 Views)