Another interesting feature of SQL Server Data Tools (SSDT) is a unit testing. SSDT enables to develop and execute unit tests interactively in Visual Studio. You can write tests for stored procedures, functions and triggers.
To create a simple database unit test project you need Visual Studio + SSDT, of course, and a database project (how to create it I wrote in this post).
- Open your database project in Visual Studio
- Find the object to be tested in Solution Explorer
- Right-click and select Create Unit Tests
- In Create Unit Tests window check that only one database object is selected (on which you right-clicked earlier).
- Choose the type of test project (Visual Basic or C#). This does not influence the database tests, it’s just a language of test project. As you see later all the work around the test will be made in the graphical interface of test designer.
- Type the name of your test project and the name of a test class.
- Press OK button.
- In SQL Server Test Configuration choose an existing connection (I’ve created it earlier during the creation of database project) or create a new connection, then press OK.
- Visual Studio will create a database test project and unit test. This unit test will be opened automatically in Test Designer.