Alex Rivera | Logout

CLR SQL Stored Procedures Testing with Unit Test Project

Asked 2009-06-22T17:43:09.960
10

I'm just getting into using VS2008 to write clr stored procedures for SQL 2008. When writing c# code I am used to having a separate 'Test Project' where I would place all my unit testing code, however it appears at first blush that I can't have the same setup with a clr sql project with stored procedures. It 'feels' like this can be done, and I'm missing a couple of configuration parameters, but I'm not sure what those might be.

I am using

  • Visual Studio 2008
  • MS Test
  • MS SQL 2008

My requirements are:

  1. debug the stored procedure in the visual studio debugger
  2. have a bunch of unit test to test the stored procedures

Does anyone know how I can have the unit test project properly depoly the stored procedures to the server, connect up to the sql server, and allow me to step through the unit test to the stored procedures that are sitting on the server?

****UPDATE****

Thank you to everyone for the answers so far, however they are not excatly what I'm looking for.

Mark Seemann's answer below is an interesting approach that I did not know about, and I will certainly use when it comes to resetting my database to a known state. However, I am looking to debug CLR stored procedures, and it doesn't appear Mark's method will allow me to step from my unit test project, through to the SQL server, and debug the code sitting on the server.

I am looking to actually debug the C# sitting on the server, much like the solution pho3nix listed below. However, using this standard approach you need to write your test scripts using a 'Test.sql' file and not using a unit test project from within Visual Studio.

Edit
Report

1 Answer

2

When create a project i have a treeview node with database and an item named SQL Server Project.

alt text http://img514.imageshack.us/img514/8523/81345560.jpg

Next when project template is created i get Test Scripts (Test.sql) where i can test all my SQL Server CLR classes, using common sql procedures and commands.

alt text http://img17.imageshack.us/img17/7826/38591345.jpg

With this you can have an development interface for CLR with debug. Test.sql is like an Unit Class for CLR classes.

PS. Don't forget active CLR in your SQL Server Configuration.

answered 2009-07-01T09:23:43.677

Your Answer