While writing UI automated tests, I've come across situations where test dependency looked like a must. For example, say I have two tests, where the second is dependent on the success of the first. I can add dependency (using
TestNG) on the first test so that the second is executed only when the first succeeds.
But most programmers (I suppose
xUnit users) support independent tests. That is, instead of being dependent on the first test, the second would need to bring the system to the right state before executing. To achieve this, the second test might invoke some common methods which would do the same operations as that of the first.
The problem I see with this approach is execution duplication. The first test is executed. Then the "independent" second test is executed (or it could be executed before the first, as there is no order of execution) which would essentially do the same things as the first test in order to bring the system back to a state where the second can be executed. So, this would take more time over all.
Do you write independent tests? If so, how do you cope up with execution time?