[Tutor] Class tests

alan.gauld@bt.com alan.gauld@bt.com
Mon, 15 Jan 2001 09:19:24 -0000

> I have just finished coding a class withe several class methods, can
> someone show me how to programmatically test each function in 
> the class safely?

Depends on how you define programmatically.

I'd suggest the python interactive prompt...

>>> c = Foo()
>>> c.method1(1,2,3)
>>> print c.someAttribute
>>> c.method2(2,34)
>>> print c.anotherAttribute
>>> etc...

Once you are happy it works you could put those tests in 
a "test" function for future regression testing:

def test():
   c = Foo()
   # ... etc

and have the usual stanza:

if __name__ == "__main__": test()

If you are using IDLE you can save your interactive session then 
edit out the prompts etc in Notepad or whatever...


Alan g.