Single Transaction Unit Testing in SQL Server

Running your SQL Server database unit tests within the scope of a single transaction allows you to roll back any changes that the test enacted after the test ends. This article propose a step by step approach to achieve this goal. You start to create a transaction in your Transact-SQL test script that uses BEGIN TRANSACTION and ROLLBACK TRANSACTION. Then you will create a transaction for a single test method in a test class and then a transaction for all test methods in a given test class.