Skip to content

UnitTest

tSQLt 101

In the previous post on unit testing, I tried to demonstrate how a bug can be created in a pretty innocuous fashion.  Unit testing is common in most development platforms, but as always, SQL has to be different.  SQL has state – mostly because of the data within the database.  If you have some C# code, and you want to completely re-write it, go ahead.  As long as the inputs, outputs, and other behaviors are the same, you should be fine.  Not so with SQL, which makes unit testing a little trickier.

There are several unit testing frameworks out there.  The one I have been using is tSQLt.  Although it is powerful, the documentation left me lost. In a series of articles, I would like to demonstrate how to set up tSQLt, and how to set up a basic test.  I will then go into some more details about building a test framework of many tests, and ways to automate the testing, hopefully elaborating on the documentation as I go along.Read More »tSQLt 101

SQL Unit Testing 101

So, what is Unit Testing? According to Wikipedia (http://en.wikipedia.org/wiki/Unit_testing)

In computer programming, unit testing is a method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine if they are fit for use. Intuitively, one can view a unit as the smallest testable part of an application. In procedural programming a unit could be an entire module but is more commonly an individual function or procedure. In object-oriented programming a unit is often an entire interface, such as a class, but could be an individual method.  Unit tests are created by programmers or occasionally by white box testers during the development process.

Quite a mouthful there.  In my experience, a unit test is a small piece of isolated code that gets tested to make sure that it meets the requirements specified for it.  For example, let’s say you have a function that multiplies a number by two. Given an input of 12, you expect an output of 24.Read More »SQL Unit Testing 101