Make your code covered

1 06 2006

I committed a big chunk of code to Cheesecake yesterday, along with a bunch of tests. But how can I be sure I actually covered all of the code? Of course nothing will substitute good suite of tests, but I thought trying out a coverage tool won’t be a bad idea. To install coverage simply download a one-file module and drop it into your PYTHONPATH. You may also think about making an alias for it, so you can easily call it from the command line:

$ alias coverage='python /usr/lib/python2.3/\
site-packages/coverage.py'

I wanted to check what code is executed by current set of tests that Cheesecake have. I’ve used nose runner, with a special option:

$ nosetests --with-coverage

After about 20 seconds it finished its work. Results can be seen by invoking coverage directly. For the Cheesecake package I wanted to check only few modules, because not all are written by us. So the command line went like that:

$ coverage -m -r cheesecake/_util.py\
cheesecake/cheesecake_index.py cheesecake/codeparser.py\
cheesecake/config.py cheesecake/logger.py

Results were as follows (stripped out – irrelevant here – line numbers of not-covered statements):

Name Stmts Exec Cover
cheesecake/cheesecake_index 633 410 64%
cheesecake/config 35 29 82%
cheesecake/_util 47 40 85%
cheesecake/logger 80 70 87%
cheesecake/codeparser 89 87 97%
TOTAL 884 636 71%

As you can see, codeparser code (which I was working on yesterday) is covered quite well. Results also clearly show we have a lot of work to make Cheesecake tested appropriately. 64% is certainly not enough.

HTML table was generated by cover2html.py script.

Advertisements

Actions

Information

One response

8 06 2006
Mousebender » Blog Archive » This episode is sponsored by the __getitem__ and __metaclass__

[…] I’ve refactored most of the code I wanted to change, so I’m pretty happy with it now. Side effect of rewrite is much better coverage score (especially when you compare it to the last results): […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: