Unit Testing - Is it bad form to have unit test calling other unit tests

IMHO, you should do one of the following:

  • Create a method that returns a valid call, and use it separately for both tests (not one calling the other)
  • Mock the valid call for the ShowCallMessageTest

Refactor the setup to another method and call that method from both tests. Tests should not call other tests.


To offer a counter point:

I strongly believe that well designed unit test should depend on one another!

Of course, that makes sense only if the testing framework is aware of these dependencies such that it can stop running dependent test when a dependency fails. Even better, such a framework can pass the fixture from test to test, such that can build upon a growing and extending fixture instead of rebuilding it from scratch for each single test. Of course, caching is done to take care no side-effects are introduced when more than one test depends from the same example.

We implemented this idea in the JExample extension for JUnit. There is no C# port yet, though there are ports for Ruby and Smalltalk and ... the most recent release of PHPUnit picked up both our ideas: dependencies and fixture reuse.

PS: folks are also using it for Groovy.