Reputation: 1
Is there any way to run tests within tSQLt test class in a specific order?
To my knowledge, every test is run within a transaction (meaning at the end all data will be rollback). Can we make dependent tests in a run in a particular order so that the test will rollback only after all tests are performed?
I need to do this because my data is dependent on one after another.
Upvotes: 0
Views: 163
Reputation: 11773
Why do you write tests? I assume to achieve a goal. But what is that goal?
That goal is in the end (I assume again) to spend less time hunting down hard to find defects and more time delivering value to the customers/stakeholders.
Now, writing tests has an overhead. We need to keep that overhead as small as possible, otherwise we end up going from wasting time on defects to wasting time on tests and as a result we still are slow delivering value.
One of the ways to keep that overhead small is the pay attention to writing tests that are easy to read, understand, and maintain. And one of the most important parts of that is to keep each test independent of all others and as much as possible independent of the outside world.
That means that each test should set up the environment which includes creating the data it needs and cleaning up afterward. tSQLt handles the cleanup part for you courtesy of the transaction each test is executed in.
On the other hand, writing tests that depend on each other creates a maintenance nightmare and in addition can lead to ambiguous test results. (Did this test fail because code in the test or code outside of the test did not work?)
So, to answer your question, tSQLt does not allow you to specify test order and for the reasons above you should not try to circumvent that.
Upvotes: 2