This blog post describes how easy it is to install the tSQLt framework.
Don’t know much about tSQLt? If you are serious about dealing with data in SQL Server then you should be as serious about unit testing the changes you are making to your stored procedures, functions and the like.
In fact I wrote a blog post about unit testing here:
So I am assuming that you have realised how important it is to unit test your data and code so here’s how to install tSQLt to your database.
First – go to the tSQLt website:
and go to download the framework:
The direct URL is http://tsqlt.org/download/tsqlt/
You will get a zip file with some files in it:
Which is a script that allows you to create a database and run your first unit tests. It’s a great example and you can follow the documentation at https://tsqlt.org/user-guide/quick-start/
Which is a script to enable CLR. This is partly why you should only run tSQLt on your DEV or selected TEST databases.
This is the framework itself.
We now run the SetClrEnabled & tSQLt.Class scripts and voila – we have tSQLt in our database and can now write or run all the unit tests we want.
I guess at this stage you might ask – why do I need to enable CLR – well let’s say you don’t enable it and just run tSQLt.Class.sql – you will get the following error:
So yeah – enable CLR and then when you run the tSQLt.Class.sql script – things will go much better:
So now you can start writing your own tests. The tSQLt framework adheres to the three A’s of unit testing:
The tSQLt website has some great examples and tutorials and honestly – the learning curve is very small – I’d say most Data Professionals can be up and running unit tests within 1-2 hours.
So go visit
or these other great sites:
and in no time at all you will be writing your very own unit test.
In my opinion tSQLt is that sweet spot of easy to use and comprehensive enough to make a difference.