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

后端 未结 8 1929
遥遥无期
遥遥无期 2020-12-10 23:56

I have a unit test called TestMakeAValidCall(). It tests my phone app making a valid call.

I am about to write another test called TestShowCallMe

8条回答
  •  情话喂你
    2020-12-11 00:56

    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.

提交回复
热议问题