[TIP] testing class properties and internal methods

m h sesquile at gmail.com
Mon Mar 5 14:37:35 PST 2007

On 3/5/07, Nate Lowrie <solodex2151 at gmail.com> 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?

I think this is a case where knowing the coverage of your tests is
important.  Since your private methods are getting called by other
methods (presumably), they are getting instrumented at some level.
The hard part is trying to determine that "level".  Code coverage
(coverage.py, figleaf, trace) can give you some indication of that
level.  Then I would write tests that call the public methods yet
cause the private methods to test the uncovered lines.  That way you
can change the implementation below, while still keeping your
unittests the same.


More information about the testing-in-python mailing list