If you have three tests A, B, C and each tests a specific scenario, where B depends on A and C depends on B and A. How do you deal with that? Is it a case where there should not be three tests in the first place, but rather merged into one or are dependencies normal.

There are also situations where you have three tests A, B, C and each tests a different scenario but B includes test A and C includes test B and therefore test A. Is this normal or is this best avoided? If it is to be avoided, how should the tests be written?


2 Answers 2


Keeping each test separate, but dependent on each other, may introduce erroneous failures if the prerequisite tests have not completed or have failed. Each test should be independent of another.

I would cascade the tests in this example:

  • Test #1 = A
  • Test #2 = A + B
  • Test #3 = A + B + C
  • 2
    This is a reasonable approach, but as always, it depends. If you are in a time-critical situation, and the risk of finding bugs is low, it may be preferable to just execute Test #3 = A + B + C. Commented Nov 12, 2013 at 19:03

It depends.

Some of the factors involved in deciding whether to try to make tests independent are:

  • Resources - if you have to run a very large number of functional and GUI automation tests (which is far from ideal, but is still something that happens), and you have limits on how much time or server resource you have available, performing the setup then running all the dependent tests in a series may be the most effective option you have.
  • Application complexity - the more complex the application, the more likely it is you will have to go through a large number of common steps to reach the function you actually want to test. For instance, you may be performing identical steps with users who have different privilege levels. Do you duplicate all the code or do you break it out and run it as dependent tests?
  • Tolerance for repeated code - Even if you break out common steps into their own routines, you'll still end up with a lot of repetition in the larger applications. For instance, you have two tests where you're logging in and creating orders for customer X. To make these independent, you need to include the log in and creation of customer X's account as well as the order in each test - that's a lot of duplication there. A change to the process flow can make a real mess of your tests before they hit the test you want - namely creating the order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.