Unit-testing with dependencies between tests Unit-testing with dependencies between tests python python

Unit-testing with dependencies between tests


Personally, I wouldn't worry about creating dependencies between unit tests. This sounds like a bit of a code smell to me. A few points:

  • If a test fails, let the others fail to and get a good idea of the scale of the problem that the adverse code change made.
  • Test failures should be the exception rather than the norm, so why waste effort and create dependencies when the vast majority of the time (hopefully!) no benefit is derived? If failures happen often, your problem is not with unit test dependencies but with frequent test failures.
  • Unit tests should run really fast. If they are running slow, then focus your efforts on increasing the speed of these tests rather than preventing subsequent failures. Do this by decoupling your code more and using dependency injection or mocking.


Proboscis is a python version of TestNG (which is a Java library).

See packages.python.org/proboscis/

It supports dependencies, e.g.

@test(depends_on=[test_readCsv])public void test_readCsv_duplicateColumnName() {   ...}


I'm not sure what language you're referring to (as you don't specifically mention it in your question) but for something like PHPUnit there is an @depends tag that will only run a test if the depended upon test has already passed.

Depending on what language or unit testing you use there may also be something similar available