Friday, October 06, 2006

On unit testing

I've been hacking on the Buildbot for a month or so now. I've released two patches for it, a Bonsai Poller and a Tinderbox Mail Notifier. I noticed recently that Buildbot has a lot of test cases in it's tree. I've heard the phrases "unit test" and "test case" before but I didn't know what they were until today. My patches are more or less complete and have been tested but I still think it would be nice to have test cases for them. The buildbot tree will change, bonsai and tinderbox may change, and this should be a relatively simple way to get me introduced to the concept of unit testing.

I spent an hour this afternoon reading Buildbot test cases and other unit testing documents. The Buildbot uses Twisted's unit testing framework for it's tests. I found the docs for those here. This went into the specifics of writing test cases with Twisted but after reading it I still didn't feel comfortable with the concept. There was a link to Dive Into Python on the Twisted page. This is an excellent read for anyone new to unit testing. It goes from no source to test case to working code.

I've done much of what is involved in making a test case without actually making a test case. One of the key things I like about unit testing is that it defines your API. I was chatting about this in #seneca and shaver said "that also has the nice effect of keeping you honest about what you really _need_". This is a very good thing for someone like me! I went through 3 or 4 revisions of my BonsaiPoller classes before coming to the final version. I don't think this is necessarily a bad thing but I know this happened because I didn't think enough about what it should look like before attempting to implement it. Before writing the final revision I actually wrote a script that defined how I was going to use the class. Looking back on it, that was a rudimentary test case. It wasn't well organized, it wasn't testing small pieces at a time, but from a design standpoint it accomplished the same thing.

I see lots of similarities to unit testing and things I've encountered in my classes. We often get "test mains" from professors to test our assignments before handing them in. These are often in the form of small tests to every part of our classes. In my systems course we just finished doing Scenarios. To me, a scenario seems like a test case for use case description. There is obvious differences but while a test case tests the validity of code, a scenario tests the validity of a use case description.

Unit testing is very interesting! I plan to adopt it whenever I can. I expect that I will go from idea to working code quicker if I do it right.

9 comments:

Anonymous said...

Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

Anonymous said...

It's got an operation panel which will tailor or customise your work out by possibly modifying the incline or the resistance as it spins.

My website - adjustable dumbbell set

Anonymous said...

hello!,I love your writing very so much! proportion we keep
in touch more about your article on AOL? I need a specialist on this house to solve my problem.
May be that's you! Looking ahead to look you.

Feel free to visit my site; relevant webpage

Anonymous said...

Whats up this is kinda of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with
HTML. I'm starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

Feel free to visit my web site http://smithery.co/making/folksy-Invisible-economies-and-artefact-cards/

Anonymous said...

An outstanding share! I've just forwarded this onto a coworker who has been doing a little research on this. And he actually ordered me breakfast due to the fact that I stumbled upon it for him... lol. So allow me to reword this.... Thank YOU for the meal!! But yeah, thanks for spending some time to discuss this topic here on your blog.

Check out my web site - brushstroke.com

Anonymous said...

Superb, what a website it is! This blog presents valuable information to us, keep it up.



my homepage: linked internet site

Anonymous said...

It's a pity you don't hаve a ԁonаte buttοn!
ӏ'd without a doubt donate to this brilliant blog! I guess for now i'll settlе
foг bοokmarkіng аnԁ adԁing yοur RSS feeԁ to my Googlе acсount.
I look forωaгd tо nеw upԁates and will talk about thіѕ website with mу
Faсebooκ grouр. Chat ѕοon!



Also ѵiѕit my wеb-site: stock options training

Anonymous said...

Your front leg really should make a ninety diploma angle for the knee.


Here is my web blog :: just click the up coming article

Anonymous said...

It can be inexpensive adequate for your household health and fitness
center, but is so full of functions it could healthy in just as quickly in health
and fitness centers and personal gyms.

My blog post ... Top