[Tutor] How to test a class in python?

Marcos Almeida Azevedo marcos.al.azevedo at gmail.com
Tue Mar 3 07:25:44 CET 2015


On Mon, Mar 2, 2015 at 12:41 PM, Danny Yoo <dyoo at hashcollision.org> wrote:

> On Sun, Mar 1, 2015 at 11:41 AM, Alan Gauld <alan.gauld at btinternet.com>
> wrote:
> > 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 ?
>
>
> Depending on the design of the class, there might be a little bit more
> set-up involved.  But the ideas are similar.
>
>
> In a test case for a function, we have a few things in hand:
>
>    1.  The function being tested.
>    2.  The parameters we're going to pass as inputs to that function.
>    3.  The expected output we want to see if the function is behaving
> properly.
>
>
> In a test case for a class, we have a few more things in hand.
>
>    1.  The class being tested.
>    2.  The parameters we use to create the class instance.
>    3.  The particular method of the class that we're testing.
>    4.  The parameters we're going to pass as inputs to that method.
>    5.  The expected output we want to see if the method is behaving
> properly.
>
> So you can see that the core concept for testing is the same: we
> express the things that are going to change, and we also say what the
> expected result is supposed to be.  It just so happens that classes
> can have a lot more state, and this can contribute to a few extra
> steps to do the test set up..
>

I suggest PyUnit for easier testing.
Here is a very good guide: http://pyunit.sourceforge.net/pyunit.html



>
>
> Do you have a particular class in mind?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Marcos | I love PHP, Linux, and Java
<http://javadevnotes.com/java-double-to-string-examples>


More information about the Tutor mailing list