The No Interdependency guideline
First, I would like to elevate this from a guideline to a principle. This principle ensures that the unit test does not alter a state permanently; or, in other words, executing a unit test should not persist data. Based on this principle, we have the following rules:
- Test A shouldn’t affect test B.
- It doesn’t matter whether test A runs before test B.
- It doesn’t matter whether we run test A and test B in parallel.
If you think about it, a unit test is creating test doubles and doing its operations in memory, and as soon as it finishes execution, all the changes are lost, except the test report. Nothing is saved in the database, in a file, or anywhere, because these dependencies were all provided as test doubles.
Having this principle in place also ensures that the test runner, such as Test Explorer, can run the tests in parallel and use multi-threading if needed.
Ensuring this principle is a shared responsibility...