Sample Custom Validation and Extraction Rules for Web Tests in Visual Studio Team System 2008

If you haven't seen Web Tests in Visual Studio 2008 Team Suite and Tester Edition (aka. Visual Studio Team System), you really should do yourself a favor and take a look.  They allow you to write and record unit tests that will exercise and validate a running web application or web site. 

The basic idea is that you record a path though an ASP.NET application and the web test recorder records the requests and responses to/from the server.  Once you have the basic recorded test, you can then customize it to send different data to vary your test and also add validation and extraction rules to check that you're getting the response you expect from the application.

The out-of-the-box validation and extraction rules are pretty good but are really just the start of what you'll need to validate your running app.  If you're going to invest time in creating web tests, you'll definitely need rules other than what comes with VSTS.

Here are some of the custom validation and extraction rules that I've written and use regularly:

  • Validate ASP.NET Label Value
  • Extract ASP.NET Label Value
  • Validate ASP.NET GridView Row Count
  • Extract ASP.NET GridView Row Count
  • Text Exists Inside of HTML Tag

Downloads:

To use the rules in your VSTS Web Tests, download the binaries, and add references from your VSTS Unit Test project to both of the DLLs in the zip: HtmlAgilityPack.dll and Com.Benday.WebTesting.WebTestRules.dll.  Once you've added the reference, these rules should show up in the Add Validation Rule and Add Extraction Rule dialogs.

Here's an image of the Add Validation Rule dialog with the custom rules are circled in red.

image

Here's an image of the Add Extraction Rule dialog with the custom rules are circled in red. 

image 

-Ben

 

If you're looking for help installing or configuring Team Foundation Server or want guidance on using and adopting Visual Studio Team System, please contact me via http://www.benday.com.

My slides from DevTeach Toronto 2008

I spoke at DevTeach Toronto 2008 a few weeks ago.  Here are the two talks I gave with links to download my slides.  Enjoy.

Talk #1: Customizing the Team System Web Test Framework (slides)

At first glance, the Web Tests in Visual Studio Team System might not seem very powerful or interesting but the web test framework can actually do a lot – it just takes a little customization.

In this session, Ben will show you how to create custom Validation Rules, Extraction Rules, and Web Test Plugins. Then he’ll show you how to create data-driven Web Tests so that the data sources are under version control along with the test. (It’s harder than you think.) Then finally, Ben will show you how to tie it all together and make it run as part of your Team Build.

Talk #2: Object-Relational Mapping in the Microsoft World (slides)

It’s coming. Some developers have pushed back against it for a long time and called it the domain of hacks and crazy people but it’s coming. Object-Relational Mapping – also known as ORM – has been viewed with passionate skepticism for years but with the LINQ to SQL and Entity Framework, Microsoft has started to publicly endorse this data access technique.

In this talk, Ben will compare three of the major ORM solutions: LINQ to SQL, Entity Framework, and NHibernate. He’ll show their strong and weak points, and discuss how you should incorporate them in your n-tier software architecture. Along the way, Ben will show you how ORMs can help you to manage database schemas and why that actually makes unit testing easier plus demonstrate how to do some basic tasks like row auditing. When we’re done, you’ll have a good handle on ORM in the Microsoft world and hopefully agree that ORM is not just for hacks and crazy people.