Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « SQL Server Denali Feature PacksTRY_CONVERT in SQL Server Denali CTP3 »
    comments

    Yesterday, I attended a training class at Microsoft’s facility in Malvern, Pennsylvania. This training class was led by Sebastian Meine (sqlity.net) and Dennis Lloyd (curiouslycorrect.com).

    The class was from 9:00 am to 5:00 pm with a short break for lunch. During the class, Dennis and Sebastian explained how to use tSQLt (http://tSQLt.org) to write unit tests for your database code. tSQLt is a frame work that can be freely downloaded and applied to your database, allowing you to quickly and easily write unit tests. After learning about the framework and working through the exercises during the class, it is immediately obvious to me how this framework and the techniques explained during the class will benefit my organization.

    Specifically, writing unit tests for the database will allow me to re-factor the code in a safe way, making sure that the code doesn’t break because I can easily run all of the unit tests for the database, or just the unit tests associated with the code I am in the process of changing.

    Since I already have dozens of views, hundreds of functions and thousands of stored procedures, I cannot take the time to write all the unit tests required for the existing stuff, but I will create unit tests for the new code I write and also unit tests for any bug fixes with the existing code. Over time I will have a set of unit tests for my database code that will undoubtedly allow me to spend less time fixing defects and more time writing new functionality.
    With my application, most of the bugs discovered by the end user are data related. The tSQLt unit testing framework will allow me to write tests for those bugs and then have confidence that the bug will not return (in the released version of the software).

    Thank you Dennis and Sebastian for teaching this class and showing me this framework. I certainly appreciate it and will be sure to start using it.

    About the Author

    George has been developing software professionally for 19 years, first for the department of defense, and then for various other companies. In 1998, George started his software company, Orbit Software, specializing in School Bus Transportation software. His specialty is refining SQL Server queries to deliver optimal performance.
    Social SitingsTwitterLTD RSS Feed
    Instapaper

    6 comments

    Comment from: Christiaan Baes (chrissie1) [Member]
    Christiaan Baes (chrissie1) u should make them part of your build process, and if one fails the build should fail and someone should be tortured.
    07/20/11 @ 11:31
    Comment from: SQLDenis [Member] Email
    SQLDenis I am pretty sure that we use the same SQL unit test framework here

    I believe it had some issues with procs that had #temp tables but am not 100% sure

    It is nice to have things like this, the more you can automate the better...I think the rule is if you have to do it more than twice script it out/automate it
    07/20/11 @ 11:58
    Comment from: Alex Ullrich [Member] Email
    Alex Ullrich I agree, this was a great seminar. The tSQLt framework makes it easier than I thought possible to use established unit testing practices for testing SQL code.

    I plan to write a little more about the framework from the technical side, if you don't beat me to it :)
    07/20/11 @ 11:59
    Comment from: Dennis Lloyd [Visitor] Email · http://www.curiouslycorrect.com
    Dennis Lloyd Hi George,
    Thanks for the review of the class. We were glad to have you in attendance.

    In response to Christiaan's comment, tSQLt can definitely be used in the build process. You can check out http://tsqlt.org/177/integrating-tsqlt-with-cruise-control/ for more information.

    And for SQLDenis, can you tell us more about the problem you've experienced with #temp tables? You can either email me directly or send a message to the tSQLt Google group: https://groups.google.com/group/tsqlt

    Happy TDDing!
    -Dennis
    07/26/11 @ 12:27
    Comment from: Andrew Russell [Visitor]
    Andrew Russell Hi George,

    I know this comment is some time after your post, but I thought it would be worth mentioning a new beta product from Redgate called SQL Test (in case you hadn't already come across it). This is a small plugin for SQL Management Studio that works with tSQLt and gives you a funky GUI Test runner that makes creating tSQLt and running tSQLt tests very simple.
    02/02/12 @ 07:06
    Comment from: George Mastros (gmmastros) [Member]
    George Mastros (gmmastros) Andrew,

    I am aware of Redgate's SQL Test. In fact, they approached me several months ago when they requested that I re-write SQL Cop checks to include in SQL Test. I have re-written a couple of the tests already and will finish up the rest in a couple weeks.
    02/02/12 @ 07:10

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)