Welcome to MSDN Blogs Sign in | Join | Help

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

Published Friday, July 14, 2006 11:30 PM by SachinRe

Comments

# Creating your first database unit test » Wagalulu - Microsoft » » Creating your first database unit test

# Creating your first database unit test | Database | SQL Server | Oracle | MySQL | DB2 | PostgresSQL |

# Sachin Rekhi on Database Unit Testing

I don't know how popular the blogs from the Team Edition for Database Pros team have grown, so I wanted...
Monday, July 17, 2006 4:43 AM by Rob Caron

# Sachin Rekhi on Database Unit Testing » Wagalulu - Microsoft » » Sachin Rekhi on Database Unit Testing

# VSTS Links - 07/17/2006

Dave McKinstry on hints for expediting Team Build script deployment.

Roy Osherove on using Source...
Monday, July 17, 2006 2:22 PM by Team System News

# Julian Kuiters - What I'm Reading 19 July 2006

Tuesday, September 12, 2006 11:26 PM by Julian Kuiters - What I'm Reading 19 July 2006
Anonymous comments are disabled
 
Page view tracker