I wanted to show you how easy it is to create your first database unit test using Visual Studio Team Edition for Database Professionals. So we’ll walk through exactly how to create a unit test for the CustOrderHist stored procedure in the Northwind database.
§ Open Visual Studio IDE
§ Select Test -> New Test… from the top-level menu
§ In the resulting Add New Test dialog
Select Database Unit Test
Pick the type of test project you wish to create (Either C# or VB)
§ Specify the desired name for the new test project
§ Specify the database connection to run the test against
§ The Database Unit Test Designer will appear
§ Add a new test method by selecting the + button on the top of the designer.
§ Name the new test and press OK
§ Add the following T-SQL to the main editor window in the designer:
DECLARE @CustomerId nchar(5)
SELECT @CustomerId = 'EASTC'
EXEC dbo.CustOrderHist @CustomerId
§ Select the inconclusive test condition in the Test conditions panel on the bottom half of the designer. Delete it.
§ Add a row count test condition by selecting Row Count from the drop down and pressing the + button.
§ Set the expected rows in the Properties Window to 19.
§ You are now ready to run your test! Open up the Test View. Select the Test -> Windows -> Test View menu item.
§ Right-click on the test and select Run Selection.
§ Review the results in the Test Results Window.
§ And your test passed!
You have just successfully created your first database unit test J
In later posts I'll explain each of the crucial concepts that you just walked through in order to build this test.