In my previous research about database unit testing in SQL Server Data Tools I’ve found that data inserted into tables during test had not been deleted automatically. You should create a cleanup action manually.
- Choose an item Post-test in dropdown list shown below.
- Click the link Click here to create in the center of Test Designer.
- Write T-SQL code to delete test data.
I truncate table Clients and run my test. Test is OK and there’s no test data in Clients table. So I could run my test as many times as needed.
There’s a possibility to include test condition even in post-test phase. Wonderful, I’ll check that test data is deleted successfully.
- Add simple SELECT command to query rows with test guid.
- Add test condition to check no data is returned. This can be made with Row Count = 0 condition or Empty ResultSet condition. I choose the second.