Hash: SHA1

Adam GROSZER wrote:

> I'm somewhat vary on unittests. I've seen some damn cryptic ones that
> took a lot of time to decipher.
> A doctest somehow forces you to dump your mind (well at least that, if
> we're not that brilliant techdoc writers).
> OTOH I think most unittests maybe have some comments, worst case they
> don't even use "speaking" variable names.
> I'm not sure whether we can enforce such rules (super thorough, no
> shortcuts-taken, well commented) if we can't easier ones.

I agree that the unit tests themselves often need cleaninng up:

- - They should avoid importing the module-under-test at module scope,
  and minimize any other imports as well:  import errors should cause
  tests to fail, not to be masked.

- - They need to be broken up, so that each testcase method tests exactly
  one code path through each method (or function) under test.  Each
  testcase method should be named to indicate which method/function it
  tests, and which set of preconditions.

- - The local variables need to have *much* better names.

- - They need to avoid using test fixtures from other modules:  having
  to stop to look up exactly what the fixture means or does is a
  "pipeline stall" for the CPU of the programmer tryihg to understand
  the test.

Doing this cleanup is part of the effort I am proposing we undertake:
getting the tests comprehensible is as important as getting to 100%
coverage, because the "lines executed" bit (syntax) that coverage
analyzers report is still not sufficient to ensure that you cover all
the semantics of the module.  Analyzing completeness on the latter
requires understanding what each method or function tested does, and how
each test exercieses it.

I have made a start on such cleanups for zope.interface:


Look particularly at the 'test_interface.py' changes:


and those to 'test_verify.py':


Note as well that I am deliberately leaving off the table the
"integration testing" which is normally done via the zope.testbrowser
layer support:  as with doctests, such tests can be useful, but I would
never rely on them for the "coverage" part of testing a package.

- --
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to