Web Application Performance Testing using Visual Studio 2010
Visual Studio's Web Performance Test
The primary vehicle for web application performance testing in Visual Studio is the Web Performance Test.
Visual Studio provides a nice GUI for designing Web Performance Test's and it integrates beautifully with Internet Explorer which allows for recording a browser session to generate a Web Performance Test.
Additionally, Fiddler's got an export to Visual Studio Web Test (aka Web Performance Test) feature which is pretty good at generating .webtest's which can be brought directly into Visual Studio
(NOTE: Fiddler export to Web Test does not capture every aspect of the request verbatim, i.e. - you may not get all Cookies, Headers or ViewState content but instead a reference to these items from the previous request in the test - so tread carefully here).
While the GUI is good for designing the basic steps of your test, it does lack some advanced features which can only be fully realized by switching over to a Coded Web Performance Test. The GUI does provide a feature for exporting a GUI based web test into a Coded Web Performance Test.
Since I am no stranger to writing code, it's no surprise that I actually prefer to slang my Web Performance Tests coded instead of tinkering around in the UI anyway.
Here's an example of a Coded Web Performance Test generated from a GUI designed Web Performance Test:Â
//------------------------------------------------------------------------------ // <auto-generated> //     This code was generated by a tool. //     Runtime Version:4.0.30319.235 // //     Changes to this file may cause incorrect behavior and will be lost if //     the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace Performance.Testing.Utilities.SampleTargetScripts {     using System;     using System.Collections.Generic;     using System.Text;     using Microsoft.VisualStudio.TestTools.WebTesting;     public class WebTest1Coded : WebTest     {         public WebTest1Coded()         {             this.PreAuthenticate = true;         }         public override IEnumerator<WebTestRequest> GetRequestEnumerator()         {             WebTestRequest request1 = new WebTestRequest("http://www.google.com/");             request1.Encoding = System.Text.Encoding.GetEncoding("utf-8");             yield return request1;             request1 = null;         }     } }
I am sure we can do better than this. Here is the same code (with non-required statements eliminated) refactored:
using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.WebTesting; using Performance.Testing.Fluent.WebTesting.Framework; namespace Performance.Testing.Utilities.SampleTargetScripts {     public class Google_Home_PageLoad : BaseWebTest     {         public override IEnumerator<WebTestRequest> GetRequestEnumerator()         {             var request = FluentRequest.Create("http://www.google.com");             yield return request;             request = null;         }     } }
So that's a bit better. We can now use a common base class BaseWebTest along with a Fluent API to create a WebTestRequest in a single line of code which will use sensible defaults (i.e. - setting the encoding to UTF8, etc). The BaseWebTest class simply sets the PreAuthenticate = true statement in the constructor.
Need to add form post parameters? Query string parameters? JSON data? The FluentRequest API will support it.
Have a look at the Performance Testing Utilities as well as the FluentRequest API on github.
Stay tuned for more on Web Application Performance Testing.












