Total Pageviews

Friday, October 12, 2012

TsqlUnit Testing Framework

http://www.devproconnections.com/article/tools-and-products/tsqlunit


http://www.sqlmag.com/content1/topic/unit-test-your-stored-procedures/catpath/tsql3/page/1
http://msdn.microsoft.com/en-us/library/aa175796%28v=sql.80%29.aspx

Test-driven development (TDD) alters the process of writing code so that change is not only possible, but desirable. Development revolves around three basic activities: writing a test, writing code to pass the test, and refactoring the code to banish duplication to make it simpler, more flexible, and easier to understand.

What makes TDD so effective is the automation of your programmer (unit) tests, and the great news is that the only tools you need are available for free on the Internet. These are not reduced functionality versions of a commercial product, but high-quality software made available by fellow developers.

Test-driven development allows you to defer decisions until you understand the problem better. You don't need to produce a perfect architectural design up front at a time when you have the least knowledge about how the product will develop.

There are also benefits to TDD that are much easier to grasp. It encourages communication by making your programs self-documenting—the set of tests you develop show how the code works in a way that a manual can't. It encourages feedback by asking you to view your code from the perspective of someone writing a test for it, which helps you create objects and components that are more loosely coupled and cohesive. It encourages simplicity by letting you defer big decisions so you can concentrate on getting the little ones right. Finally, it gives you the courage to push the boundaries of your code by giving you a set of tests that tell you immediately when something breaks.



Before I tell you about a testing framework for T-SQL, here are reminders of two very basic principles:
  • First, you need a database with good test data. By "good data," I mean live data from the real world. No matter how good a programmer you are, you'll never be able to mock up data adequately for an application. Even if the legacy system you're replacing is made of paper, get a data entry person to enter data into some tables. Do what it takes to get real data. [There are test data generators, though. See my tip, "Generating Test Data," in this issue.–Ed.]
  • Second, you shouldn't be developing against a production database. You should have a development or test database that you can explode to your heart's content.
Once you have your development database up with good data, you need some sort of framework in which to run your tests. You could write your own, but why should you? There's one already available to you.


TSQLUnit is a testing framework to write tests for applications written in Transact-SQL. It follows the tradition of the "xUnit" framework that is available for almost all programming languages. TSQLUnit is open source, licensed under the LGPL license, which means that it can be used freely even in commercial programs subject to certain restrictions. See the CookBook for an introduction of how to use it.

http://www.slideshare.net/SyedAsrarali/intro-to-tsql-unit-14

No comments:

Post a Comment