Debugging Custom Validation/Extraction rules, Web Test and Load Test Plug-ins

Most of my recent posts have been about new features in VS 2010.  This post is going to show you how to debug your custom rules.  This applies to VS 2005, VS 2008 and VS 2010. 

  1. First let’s create a Test Project
  2. Then Right click on the project node and select Add –>  Web Test
  3. Record a simple web test
  4. Now add a new class to the project.  We can re-use the sample extraction rule from this earlier post: Sample Extraction Rule  Copy and paste the code from this sample into the new class file.
  5. Compile the project
  6. Right click on a request that has a post parameter and select the new rule:
  7. image
  8. Enter a context parameter name, name of the form field to extract and the index of the form field to extract.  I am going to enter _EVENTVALIDATION. Then click OK.
  9. The test is ready to run.  If you click the play button in the web test editor the test will run and the you will see the results in the Web Test viewer.  But what if your custom rule/plugin isn’t working as expected.  When I playback my test, my rule failed to find the _EVENTVALIDATION field.  


Debugging the rule

  1. First we need to place a break point in the custom rule.  For an extraction rule, place a break point in the extract method.  image
  2. Now we need to start the test.  This time we don’t want to just click play.  If you hit the drop down on the web test editor play button, you will see that there are 4 options.  This time choose Debug Test.                                                   image
  3. When the test runs, it will hit your break point.                                                                                 image 
  4. Now we can step through and see why the rule failed.                                                                  image
  5. In my case I can see that when I typed in the form field, I missed a _.  Now if I correct my mistake and rerun, I can see the value extracted into the context.                                                                                                                              image   

This shows you how to debug web tests rules/plugins.  But the same applies to load test plugins.  The load test editor play button is also a split button.  So just place your break point in the load test plug-in and choose debug test instead of play test. 

I hope this helps in debugging your custom rules.