This post discusses about creating a database unit test case in Visual Studio 2010 which verifies the functionality of a stored procedure. Creating Database Test cases helps you to identify the code defects which in-directly effects the application behavior. In order to create a database unit test, you need to VS studio 2010 test suite or ultimate version. |
Before writing a unit test case , define a schema file and create a database project and deploy to the database as shown below.
Schema file defines a table and one stored procedure to insert the data into that table.
Save the script file on to disk. Now Create a database project as shown below to test the script
Import the script into the project that we have created earlier by choosing a option import script file from project menu
Browse the file, click next and say finish.
Verify the script has been loaded into the project by expanding the schema objects in project explorer as shown below
Now deploy this scripts to database instance from the project by using the deploy option from properties window as shown below
Click the deploy solution from build menu and check the database for the deployed objects
Now let us go and create a database unit test by going to view menu and select Database Schema View then you will see the following window
Right click on the database object that you want to create a unit test as shown below
Name the project and test class as shown below
Configure the database test project as shown below
When you click ok in above dialogue then it creates a unit test for stored procedure. Save all and build the database project. Edit the unit test to insert the record in to customer table as shown below. Change the test condition to row count.
Select the test case that you have created from test view and run the test case
See the test results in results view window and check the database whether row has been inserted or not
This is a very basic example of creating a database test case where you can create unit test cases on complex database objects and share with the other developers so that any change occur on database objects would not change the application behavior by running the test cases.
Share this post : |
[…] defects which in-directly effects the application behavior. In order to create a database unit… Read more… Categories: .NET Visual Studio 2010 Share | Related […]