SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Automated Database Unit Testing

Automated Database Unit Testing

Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (540K reputation)SSC Guru (540K reputation)SSC Guru (540K reputation)SSC Guru (540K reputation)SSC Guru (540K reputation)SSC Guru (540K reputation)SSC Guru (540K reputation)SSC Guru (540K reputation)

Group: General Forum Members
Points: 540257 Visits: 44587
I've seen lots of articles that talk about unit testing of Views, Functions, and Stored Procedures like the following recent article...

In that article, they also have a link to an SSDT (http://blogs.msdn.com/b/ssdt/archive/2012/12/07/getting-started-with-sql-server-database-unit-testing-in-ssdt.aspx) article, which contains a link (http://msdn.microsoft.com/en-us/library/jj851200(VS.103).aspx) to the Microsoft site for SSDT.

With the understanding that I've never used such a tool nor have I worked for a company that has and, therefor, claim some good ignorance of the subject, I have a couple of questions.

If you've created a function the gets customer data similar to the one in the articles, how useful is a canned unit test actually going to be? When the function was originally written, someone would have to write the canned unit test and then, test the test to see if both the function and the test were written correctly. Six months later, someone has added a column to one of the customer related tables and the data in new column not only has to be added as a return from the function, but it also changes which customer will be returned for the same parameters previously passed to the original function.

My question would be, how useful is that previously written and canned unit test going to be now? My assumption is that the canned unit test isn't going to magically know what the new requirements are and that someone is going to have to write AND TEST a new canned test. Since the canned test contains mostly T-SQL, wouldn't it just be easier to write a bit of T-SQL to pass the parameters to the function, see what data came back, and be done with it instead of going through all those steps to build a test that might not be a valid test for the next version of the code anyway? Isn't someone still going to have to populate the table with known test data for this release?

Here's another one. Someone builds a "Tally-Table-Like" function to count from 1 to whatever. Is it really necessary to build a canned test for a function that will never change just so you can say it's been unit tested?

Forgive my ignorance but I don't see any advantage to all the additional steps to can a unit test and I'd love to hear what the advantages actually are from someone that has used such canned tests.

Thanks a lot, folks.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs


You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum