Creating your first database unit test
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.
Sachin Rekhi
Comments
- Anonymous
July 14, 2006
PingBack from http://microsoft.wagalulu.com/2006/07/14/creating-your-first-database-unit-test/ - Anonymous
July 14, 2006
PingBack from http://www.idoel.smilejogja.com/2006/07/15/creating-your-first-database-unit-test/ - Anonymous
July 16, 2006
I don't know how popular the blogs from the Team Edition for Database Pros team have grown, so I wanted... - Anonymous
July 16, 2006
PingBack from http://microsoft.wagalulu.com/2006/07/17/sachin-rekhi-on-database-unit-testing/ - Anonymous
July 17, 2006
Dave McKinstry on hints for expediting Team Build script deployment.
Roy Osherove on using Source... - Anonymous
September 12, 2006
PingBack from http://www.julian-kuiters.id.au/article.php/reading-2006-07-19