With Team Edition for Database Professionals, you can create database unit tests and debug the objects under tests. This is an important technique that is very useful for investigating failed database unit tests.

 

An important thing to remember here is that debugging the objects under test is enabled in Team Data, but you cannot directly debug the test script itself.

 

Below are the steps you need to go through to debug your objects under test with database unit testing.

 

Enable SQL Server Debugging on your test project

1.       Open your existing test project containing database unit tests

2.       Open Solution Explorer

3.       Right-click on the test project in Solution Explorer and select Properties

4.       On the properties page, select the Debug tab

5.       Under Enable Debuggers, click Enable SQL Server debugging

 

Add breakpoints to your database object under test

1.      Open Server Explorer

2.      Under Data Connections, expand the node of the database containing the object you wish to debug

3.      Expand the object type folder node to find the object that you want to debug

4.      Double-click the desired object

5.      Add a breakpoint by clicking the grey sidebar in the editor next to the statement you wish to set the breakpoint on

 

Debug your database unit test

6.      Open the Test View window

7.      Select the test you wish to run to exercise the object you wish to debug

8.      Right-click on the test and select Debug Selection

 

Now the test should run and you should break once you hit your first breakpoint. At that point you can use the Watch and Locals windows to interrogate variables, as well as use all the other available debugging facilities.

 

To learn more about SQL Debugging, check out this link:

http://msdn2.microsoft.com/en-us/library/zefbf0t6.aspx

 

Sachin Rekhi