Unit Testing with SQL Server

  • Comments posted to this topic are about the item Unit Testing with SQL Server

    Alessandro Alpi
    CTO Engage IT Services S.r.l.
    DBA | Team Leader
    Microsoft MVP - Data platform
    [MCP] [MCITP]

  • This seems like a good idea, but I can't imagine having time to set up these tests. Do many companies really run these types of test on their database schema? My experience has been that we don't even have time for documentation, which would have to come before unit testing.

    That said, good article explaining how to do this and I love that it included an easy to understand example.

    Be still, and know that I am God - Psalm 46:10

  • Hi david,

    thank you for this comment.

    david.gugg (3/26/2015)


    This seems like a good idea, but I can't imagine having time to set up these tests.

    When a development team starts to follow the agile development pattern, source control, build and test are the "must" artifacts. Speaking about evolutionary development on databases, covering you biz logic with tests allows you to prevent regressions and to refactor your database schemas in a reliable way. I think that evolutionary database should include test suites, always.

    Do many companies really run these types of test on their database schema?

    My italian customers didn't even hear about database unit testing. But some company switched from a waterfall approach to an agile one (like scrum) and then they started to implement test BEFORE the real biz logic (TDD manner).

    My experience has been that we don't even have time for documentation, which would have to come before unit testing.

    Actually, when we started to write tests, we tried to create them self-documented. I think that a test can describe in the best way certain features. The biz logic, for sure, should be small (ligthweight code) in order to be "testable".

    That said, good article explaining how to do this and I love that it included an easy to understand example.

    Thank you so much David.

    Alessandro Alpi
    CTO Engage IT Services S.r.l.
    DBA | Team Leader
    Microsoft MVP - Data platform
    [MCP] [MCITP]

  • david.gugg (3/26/2015)


    This seems like a good idea, but I can't imagine having time to set up these tests. Do many companies really run these types of test on their database schema? My experience has been that we don't even have time for documentation, which would have to come before unit testing.

    Hey David,

    I can't speak to how many companies are unit testing their databases, but I can tell you that I started a new job about 9 months ago and immediately started putting unit tests around the stored procedures. These stored procedures were not documented well and many times we found that the stored procedures were not working as desired. The great thing about the unit tests is that they are self documenting. You are actually documenting what the stored procedure/table/function/whatever is supposed to be doing. No need to do one before the other, because the unit test is your documentation.

    Also, I've found that it saves me quite a bit of time in the long run, yes a little more time up front when writing a stored procedure, but much quicker after to determine what problems may be occurring. Besides, I assume you're testing your stored procedures in some form or fashion...why not do it at the front end and keep the tests so they will be useful again later.

    Chris

Viewing 4 posts - 1 through 3 (of 3 total)

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