[TIP] testing class properties and internal methods
Michael Foord
fuzzyman at voidspace.org.uk
Mon Mar 5 14:48:58 PST 2007
Nate Lowrie wrote:
> On 3/5/07, Michael Foord <fuzzyman at voidspace.org.uk> wrote:
>> 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 ?
>
> Python decorator added in 2.2. Basic it is like a managed attribute.
> See http://www.python.org/download/releases/2.2/descrintro/#property
> for more info.
>
Right - they're not really very different from methods, so yes we test
their behaviour (especially as they are inevitably part of the public API).
Fuzzyman
More information about the testing-in-python
mailing list