Software QA FYI - SQAFYI

Unit Testing With Visual Studio

By: Grant Fritchey

For the purposes of this article, I'm going to assume several things, not far off from the previous article. You've got a working a knowledge of TSQL, C# and Visual Studio. I want to add the same caveat as last time, if you spot issues with my methods, since I'm not a programming expert, please let me know in the comments section. I'm also going to assume a nodding acquaintance with the Team Edition for Database Developers (because I don't want to write a how-to on using it).

Creating a Test
As with the rest of the tool, this is pretty easy. You've got a wizard supplied with the tool that can be accessed when you're looking at the Schema view of the database you're working. Simply right click on a stored procedure in the list and select "Create Unit Tests..." to get a selection list of all the stored procedures. Select the procedure or procedures you want then select an output test project (I used a C# project) to create or one that already exists in the solution.

You're then required to configure your test environment. Choose a database where you will run your tests. Optionally you can validate tests against a second database, also chosen here. You can also decide if, prior to running tests, want to build & deploy your code. All this can be edited later to modify the behavior of your tests.

The tool immediately generates TSQL that it will use to test your procedures. It declares a return value for the proc and a series of parameters based on the parameter list for the procedure. These are all correct in data type and direction (OUTPUT is picked right up). I used Adventureworks for the article. Here's a generated test script:

Full article...

Other Resource

... to read more articles, visit

Unit Testing With Visual Studio