Unit testing with SQL Server Data Tools

This is the second part on the serie about SSDT and database development and also my second blog post in collaboration with SQLShack.

Part I: Continuous integration with SQL Server Data Tools and Team Foundation Server

In December 2012, a great addition was made to SSDT: The ability to do database unit testing.

However, this feature is not available on the free edition of SSDT. For doing unit test with SSDT you will at least need a Visual Studio Professional edition or above.

As you and the team members make changes to the database schema you can verify that these changes are working as expected or if they have broken existing functionality.

Please bear over with me making so many screen dumps but I was so fortunate to get a license of SnagIt® from TechSmith so I am also trying the possibilities of the tool in this blog post. :)

Proceeding

Usually you will want to baseline your database and then run some unit tests on the changes that you have made. Personally, I have made a habit out of taking a snapshot of the database I am working with at different stages and at least once a week. This way I can always go back to the state it was before I made the subsequent changes without having to roll back changes with TFS.

Because unit testing of your database is just a “Unit Test Project”, you can create and run database unit test without a database project. However, the only way to auto-generate tests for specific database objects is to use the database project.

When creating a test project from a database project Visual Studio will automatically generate some of classes for you. Most of the plumbing will be done that way. The most important class in that regard is:
Microsoft.Data.Tools.Schema.Sql.UnitTesting;

Checking for the latest version of SSDT

First you need to check if you have the latest version of SSDT. This is done with the Check for Updates menu under the SQL menu.

Getting the latest version of SSDT
Figure 1: Getting the latest version of SSDT

You can read the rest of the post here.

– See more at: http://www.sqlshack.com/unit-testing-sql-server-data-tools/#sthash.r8D0VwE7.dpuf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: