Transactions
I have just created a unit test that, because of the way our environment has been configured, drops a series of objects prior to generating the data/objects under test. In order to maintain the integrity of the database in case of issues, I am trying to wrap the text proc in a transaction so that I can at least tidy up in the event of a problem. Obviously, just wrapping the entire test in a transaction rolls the results back and so the test just reports that it succeeds. Technically, it does since everything has been rolled back, but it's also not actually testing anything. In such a case, success is not the correct answer.
What is the recommended method for including a transaction in the test?
Answers
http://www.sqlservercentral.com/blogs/steve_jones/2010/09/21/table-variables-and-transactions/
Redgate Software
You shouldn't need to handle transactions within the test sproc itself because the tSQLt.run will roll back the transaction after executing the test anyway. That's why stuff like FakeTable is safe.
DevOps Mentor and Coach
Director of DLM Consultants
Creator of Speaking Mentors
Microsoft Data Platform MVP
Friend of Redgate
Twitter / LinkedIn
So you can fork it and/or contribute your own patches if you prefer. 😉
DevOps Mentor and Coach
Director of DLM Consultants
Creator of Speaking Mentors
Microsoft Data Platform MVP
Friend of Redgate
Twitter / LinkedIn