[Opensim-dev] Unit tests should not be coupled (WAS: Re: [Opensim-commits] r8737 - trunk/OpenSim/Framework/Communications/Tests)

Mike Mazur mmazur at gmail.com
Mon Mar 9 23:47:10 UTC 2009


Hello,

On Mon, Mar 09 2009 08:20:36 -0700
sdague at opensimulator.org wrote:

> Author: sdague
> Date: 2009-03-09 08:20:36 -0700 (Mon, 09 Mar 2009)
> New Revision: 8737
> 
> Modified:
>    trunk/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
> Log:
> * Added TXXX in front of unit tests to make sure they are running in
> the correct order. Although it might not make a difference here, this
> pattern should be followed to avoid further issues.
> 
> From: Arthur Rodrigo S Valadares <arthursv at linux.vnet.ibm.com>

Just FYI, as a rule "[unit tests] are not coupled. They run without
dependencies"[1]. Tests relying on other tests is a code smell, and
should be refactored. Here's a little more[2]:

  If tests are interdependent and (even worse) order dependent, we will
  be depriving ourselves of the useful feedback test failures provide.
  Interacting Tests [...] tend to fail in a group. The failure of a
  test that moved the SUT into the state required by the dependent test
  will lead to the failure of the dependent test too. With both tests
  failing, how can we tell if it is because of a problem in code that
  both rely on in some way or is it a problem in code that only the
  first relies on. With both tests failing we can't tell. We are only
  talking about two tests here. Imagine how much worse this is with
  tens or hundreds of tests.

The test author may know quite well that the tests are dependent on one
another and may be able to figure out where the failure is quickly. It
may take other project contributors considerably longer to understand
what's happening, though.

There's more good stuff on unit testing both at the c2 wiki
(http://c2.com/cgi/wiki) and at http://xunitpatterns.com which describe
this stuff much better and in more detail than I can.

Thanks,
Mike


[1] http://c2.com/cgi/wiki?UnitTestsDefined
[2]
http://xunitpatterns.com/Principles%20of%20Test%20Automation.html#Independent%20Test



More information about the Opensim-dev mailing list