In the first lesson, we will install tSQLt and understand what a unit test is and where we should use unit tests with T-SQL code. If, after reading through this, you can install tSQLt and know when to write a test and how to run the tests then we will be in good shape :)
What is tSQLt
tSQLt is a unit testing framework which allows us to write, execute and diagnose tests for T-SQL code. The main reasons for using tSQLt are:
- tSQLt provides a way to structure t-sql code as tests
- tSQLt provides a way to execute tests in a repeatable way by managing the setup/teardown of data
- tSQLt provides a way to isolate code and tables using mocking NOTE: we'll cover this in detail in a later lesson but, for me, mocking is the killer feature
tSQLt is not the only unit testing framework for Microsoft SQL Server but it is a great tool in any developers arsenal who writes T-SQL code that needs to be tested.