Skip to content
Advertisement

tsqlt FakeTable not rolling back after unit test executed

I have an extremely simple unit test where I am testing the functionality of a tsqlt.FakeTable. However, after running the command and inserting data, it does not roll back to the previous state.

Current table:

[product01].[batch]

enter image description here

After executing the below code, the table is not rolled back to the above. It overrides the data and I can see the temp object created under tables.

Selecting the batch table after the above code has run:

enter image description here

I haven’t written the actual assert logic, but I am confused as to why the table is not being rolled back. Any thoughts on this?

Advertisement

Answer

tSQLt tests cannot be executed directly. You need to always use one of the run methods like tSQLt.Run

If you call the test directly as in EXEC your.test;, no rollback will happen and other tSQLt features won’t work either.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement