Visual Studio has an integrated Web Test tool capable to record navigation in IE to create web tests that can be used even for Load Testing. One of the most interesting capabilities of this tool, is that it is pluggable.
Suppose you have recorded a simple test that verifies the registration procedure for a web site, this test suffer from a well known problem, whenever you will run it, it will try to register the same user again and again and it fails. Moreover, if I want to use this test in a web load test I could not use Data Driven Test because I really want a random string to be generated each time the test is run to be sure that a new username gets registered. Sounds complicated? Maybe not :)
First of all add a dll project to your solution, reference the Microsoft.VisualStudio.QualityTools.WebTestFramework library and add this class to the project.
This is all you need to generate a random string during test, overriding the PreRequestDataBinding, generate a random string, and then add to the test context thanks to e.WebTest.Context.Add() method. Now you can simply take your recorded web test for user registration, reference the project that contains this plugin-in and add a request plug-in
Figure 1: Create the plug-in project, insert the class in it and reference it from the project that contains the web test
Figure 2: Add the plugin to the request where the user is created.
Now you need to configure the plugin, it has only a property that is used to specify the name of the context parameter to use for the random string.
Figure 3: Configure the plugin and the test to use the random string
Now I run the test and verify that the username has a random value.
This simple example shows how simple is to create a plug-in for Visual Studio web test.