Debugging In SSDT Database Unit Test

“SSDT now enables you to develop, debug and execute database unit tests interactively in Visual Studio…”

I was pleased when I read this in the post in SSDT team blog.
But I was confused a little when I could not set a breakpoint in unit test as I always do in Visual Studio. Yeah! You can’t click on the grey sidebar to the left from the unit test code (it’s on the red frame on the screenshot below).
place to set breakpoint
I’ve found a topic How to: Debug Database Objects on the MSDN that describe the steps needed to debug unit test.
1) enable SQL debugging on test project:

  • right-click test project in Solution Explorer, then click Properties
  • click Debug
  • check the option Enable SQL Server debugging
enable sql debugging
2) increase execution timeout:
  • double-click on app.config in Server Explorer
app.config in solution explorer
  • set CommandTimeout in the line ExecutionContext to a greater value (for example, 300 seconds)
  • rebuild the test project to apply changes in app.config
3) set breakpoint in stored procedure we are debugging. You can open it in your database project or via SQL Server Object Explorer (View -> SQL Server Object Explorer).
4) start the debugging:
  • open Test Explorer;
  • right-click the test
  • click Debug Selected Tests
Immediately after that you will see the debug panels in Visual Studio. But it’s too early to press any buttons to step into or over. You should wait some time while Visual Studio loads and runs all the actions before it reach the breakpoint. At this time the breakpoint is shown as a white circle with a red rim.
When the execution stops at breakpoint the line will be highlighted with yellow color. Now you can step forward over the commands of the stored procedure being debugged.

Leave a Reply

Your email address will not be published. Required fields are marked *