SQL Server中存储过程的单元测试

mig*_*eia 4 sql sql-server unit-testing stored-procedures test-first

我想在一个只使用SQL Server中的存储过程和函数实现的项目中实现Test First Development.

有一种方法可以简化存储过程和函数的单元测试的实现吗?如果没有,创建这些单元测试的最佳策略是什么?

Chr*_*ood 5

当然可以进行xUnit样式的SQL单元测试和TDD进行数据库开发 - 在过去的4年里我一直这样做.有许多流行的基于T-SQL的测试框架,例如tsqlunit.红门也有这个领域的产品,我已经简要介绍过了.

Then of course you have the option to write your tests in another language, such as C#, and use NUnit to invoke them, but that's entering the realm of integration rather than unit tests and are better for validating the interaction between your back-end and your SQL public interface.

http://sourceforge.net/apps/trac/tsqlunit/

http://tsqlt.org/

Perhaps I can be so bold as to point you towards the manual for my own free (100% T-SQL) SQL Server unit testing framework - SS-Unit - as that provides some idea of how you can write unit tests, even if you don't intend on using it:-

http://www.chrisoldwood.com/sql.htm

http://www.chrisoldwood.com/sql/ss-unit/manual/SS-Unit.html

I also gave a presentation to the ACCU a few years ago on how to unit test T-SQL code, and the slides for that are also available with some examples of how you can write unit tests either before or after.

http://www.chrisoldwood.com/articles.htm

Here is a blog post based around my database TDD talk at the ACCU conference a couple of years ago that collates a few relevant posts (all mine, sadly) around this way of developing a database API.

http://chrisoldwood.blogspot.co.uk/2012/05/my-accu-conference-session-database.html

(That seems like a fairly gratuitous amount of navel gazing. It's not meant to be, it's just that I have a number of links to bits and pieces that I think are relevant. I'll happily delete the answer if it violates the SO rules)