[Zope-ZEO] Advice

Chris McDonough chrism@digicool.com
Fri, 22 Sep 2000 20:19:39 -0400


Andrew Kuchling wrote:
> 
> On Thu, Sep 21, 2000 at 03:22:59PM -0400, Chris McDonough wrote:
> >How do you define "complex object"?  Do you mean specifically without using
> >Python?
> 
> No, just something that has a very complex internal state, consisting of 45
> different states, which can be grouped into 7 over-arching phases.
> This is
> something complicated enough that you want it surrounded by an elaborate
> test suite so you don't inadvertently break one transition when fixing
> another.  Doing an effectively test suite for this in the Zope environment
> seems impossible.  You could write a Python object, test it from the Python
> command-line, and then write a layer of glue on top of it to turn it into a
> Product, but how do you test the glue?

Ah, I see what you're saying...

This is why we've been working on exposing parts of Zope (such as the
Publisher.Test module) which are useful for unit testing.  But there are
really
two ways to do this, either of which is viable.

1.  Code all of your logic in plain old Python.  Don't try to use Zope
    components while doing this.   Write tests against this logic.  Wrap
    the logic in Zope wrapper classes.  An example of this is ZCatalog,
    which is a Python Product, which wraps the Catalog, which is a
Python
    application.

2.  Code all of your logic using TTW stuff and Zope components.  Use the
    Publisher.Test.test method to call methods of your Zope components
    in unit tests.

Which one is for you is up to you.  You probably want to combine these
approaches in many cases to get end-to-end tests.

What's clear is that documentation is at the heart of the problem. 
Nobody
even *knows* about the Publisher.Test module, much less how to use it.
I've been working on some unit testing documentation which exposes it as
well as some machinery to make unit testing in Zope a little less
mysterious and painful.

The bottom line, though, is that if you're coding in Zope, you're coding
in Python.  You can use most of the tools available for testing Python
code in Zope (we have recently begun using Stephen Purcell's PyUnit unit
testing module).  I think it may be more accurate to say that figuring
out how to test is harder than actually doing it.  In any late trunk 
or branch checkout of Zope, read UNITTEST.txt in the doc/ directory
for tips.  Hopefully, I can make this information a little more
accessible by working it into the Product Developer's Guide soon.

Again, your frustration may be symptomatic of coding in instance space
instead of developing a product.  But this is not your fault, it's ours.

-- 
Chris McDonough
Digital Creations, Publishers of Zope
http://www.zope.org