[TIP] testing class properties and internal methods

Michael Foord fuzzyman at voidspace.org.uk
Mon Mar 5 14:29:11 PST 2007


Nate Lowrie wrote:
> On 3/5/07, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>> Nate Lowrie wrote:
>> > Just wondering what the thoughts were on this.....
>> >
>> > I have never tested class properties since they are basically getter
>> > and setter functions.  I also never test getter and setter functions
>> > either.
>> >
>> > Also, I have not taken to writing unit tests for the "private",
>> > internal methods not in the public interface for a class.  I do this
>> > since they are called from the public interface methods.
>> >
>> > What are people's thoughts on this?
>> >
>> >
>> Where private methods (not part of the public API) provide a unit of
>> functionality, we unit test them.
>>
>> We like to specify code behaviour in our test names (similar to some of
>> the BDD stuff I think, but I haven't had a chance to read much on this
>> yet). Specifying behaviour for the code only through the public API can
>> lead to some very complex tests / specifications.
>>
>> It is often easier to specify public API behaviour in terms of calling
>> down to private methods - and then mock out these private methods in the
>> test of the public API. The private methods can then be tested 
>> separately.
>
> Do you test python properties at all?
>

What do you mean by Python properties ?

We certainly avoid testing the language - except where we can confirm a 
bug. (Which has happened a few times with IronPython, so we put a bug 
test in which will fail when the IronPython bug is fixed, with comments 
telling us where the workarounds that we need to remove).

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml



More information about the testing-in-python mailing list