The latest version of the tSQLt unit testing framework is now available for download. This is a framework designed to help you write unit tests in T-SQL as stored procedures and execute them programmatically to ensure your code runs as expected.
Learning tSQLt
We've got a number of articles at SQLServerCentral to help you, and there are also tutorials and a quick start on the tSQLt site.
However the best way to get started with unit testing is to try and write some tests. I encourage people to write tests when they find issues, not for every line of code you write. Create a test when you have a bug reported.
Use the very simple format of AAA, which means:
- Assemble - setup your environment
- Act - call your code
- Assert - test the results with one of the assertions in tSQLt.
It's not hard, and once you get the hang of it, you'll find that unit tests are quick and easy ways to ensure that bugs that are reported don't reappear.
Add-ons
There are a few addons that make tSQLt more powerful.
Download Today
Writing tests can help improve the quality of your code. Download tSQLt today at tsqlt.org/downloads.