November 2011 Archives

Unit testing...*yawn*

| 8 Comments | No TrackBacks

It seems that too often I write code to get it to do what I want and then move on to the next bit of programming. This works great until it doesn't. So how do we take care of those times where it doesn't? We use unit testing. It is necessary tool and should be used by everyone, but it is time consuming and kind of boring.
If you haven't used unit testing before it is a series of tests you create to make your program fail. If you pass all these failing tests you don't win anything other than the joys of having to think of more ways to break your program and write even more tests. I feel that for every line of code you write, plan for about 3 million tests (this number is a dramatization). It might not really be that bad however it is tedious.
To alleviate some of this pain though there is a thing for us crazy C++ programmers called Cxxtest. It is a good way to actually test your C++ coding. You write you're testing in a header file using some basic calls such as TS_ASSERT, verifying things are doing what they are meant to do. You compile it and it does all the grunt work is done behind the scenes, it's a really nice implementation.
Unit testing might help as long as it's used properly. You do have to make sure to take small steps in writing your tests or you can miss an earlier problem. For example, during the development of getting a scanner program to work with a given parser, my partner and I kept running into a problem which introduced logic identifiers such as equal to and not equal to. After many aggravating hours of banging our heads on desks and daydreaming of going all Office Space on the system we discovered that it was actually a problem with variable names. We hadn't accounted for variable names with integers. So our test was failing because we had taken two steps in one test. It was a lesson well learned.
My problem actually was found using unit testing. Granted I wasn't looking for that problem with that specific test but it did get found. This experience alone helped me understand why testing is important and why it is also a pain.

About this Archive

This page is an archive of entries from November 2011 listed from newest to oldest.

October 2011 is the previous archive.

Find recent content on the main index or look in the archives to find all content.