Automated Database Unit Testing

  • I've seen lots of articles that talk about unit testing of Views, Functions, and Stored Procedures like the following recent article...

    http://blog.pluralsight.com/unit-testing-databases

    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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply