[Zope3-dev] Re: testing interfaces / Cookbook
Jim Fulton
jim at zope.com
Mon Apr 19 06:39:29 EDT 2004
Philipp von Weitershausen wrote:
> Yuppie,
>
>> The Cookbook uses this example
>>
>> def test_interface(self):
>> self.assert_(IMessageBoard.isImplementedBy(
>> self.makeTestObject()))
>>
>> Does it make sense to use providedBy (fka isImplementedBy) in unittests?
>
>
> isImplementedBy is deprecated. providedBy should be used when checking
> whether an object *provides* an interface. implementedBy should be used
> when checking whether a class *implements* an interface.
Yup
>> Wouldn't it be better to verify the interface?
>
>
> I guess so, though I feel that makes interfaces quite a serious
> contract. Oh well, I guess they *are* a contract, and checking that in
> unit tests couldn't hurt.
In tests, you generally want verify. Testing (or in some sort of
development tool) is the only time to use verify.
> However, sometimes you're just interested whether the object you get
> from some machinery implements an interface, i.e. promises a contract.
> That often is enough.
At "run time" you want to use implementedBy or providedBy. They are
much faster than verify.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list