[Tutor] How to test a class in python?

Alan Gauld alan.gauld at btinternet.com
Sun Mar 1 20:41:48 CET 2015


On 01/03/15 16:19, Fatimah Taghdi wrote:
> Hello I was wondering how to test a class in python is it the same way as
> testing a function ?

Possibly but it depends on how you test a function, there
are many options.

So if you tell us how you would test a function like

def square(n):
    return n ** 2

We can consider how to extend that to a class like

class Square:
    def __init__(self, side = 0):
       self.sode = 0

    def area(self):
       return self.side ** 2



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list