[TIP] 5 lines of code equals 30+ lines of single test

John Wong gokoproject at gmail.com
Tue Jul 17 21:58:55 PDT 2012


Hi guys,

Here is a simple function.

def readfile(*args, **kwargs):
    local = kwargs.get('local', os.getcwd())
    filename = args[0]
    f_path = os.path.join(local, filename)
    with open(f_path, 'r') as f:
        return f.read()


Now here is just ONE case of the readfile test code. For readabilty, I will
put in pastebin.com
http://pastebin.com/P45uc2TV

I am verifying how many times X Y C dependencies are called and what
parameters are passed to them. I think these are necessary to check (what
if one of the dependency functions called with the wrong variable).

But is this really the nature of unittest? I've read many tests code and
they all seen to be 5-20 lines..... I faint when I am reading my test
code.............. SIGH

I have some 10 lines function and it took 50 lines to test! Let alone for
each of these functions, I need to write a a few tests for each branch
case...
So if there are 10 functions, each 5 lines, I can end up with 1000 lines of
test code....

Last question, I find my patching is really really long and inconvince. How
should I patch (say they all come from os package)?

Thanks.
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120718/a4455db7/attachment.htm>


More information about the testing-in-python mailing list