This post originated from an RSS feed registered with Ruby Buzz
by Jim Weirich.
Original Post: The Simplest Unit Test Framework That Could Possibly Work
Feed Title: { | one, step, back | }
Feed URL: http://onestepback.org/index.cgi/synopsis.rss
Feed Description: Jim Weirich's Blog on Software Development, Ruby, and whatever else sparks his interest.
I was helping a friend in C++ the other day. While I religiously use a test
framework in my day to day work (e.g. JUnit for Java or Test::Unit for
Ruby), I haven’t used C++ for over three years and didn’t have
C++ Unit handy.
Then I remembered the C/C++ assert macro. We wrote a a series of small
functions that looked something like this:
void TestCanRun () {
assert( CanRun( ... ) );
assert( ! CanRun( ... ) );
// and so on ...
}
I made a TestAll() function that called all my little test functions and
arranged to have TestAll() called as the first thing in main(). If all the
assertions worked, the program completed normally. If an assertion failed,
the program would abort with an informative error message.
It worked great. I wouldn’t leave production code like that, but it
was a great way to introduce Test Driven Design to someone who had not seen
it before, without getting into all the nitty-gritty details of setting up
a full blown test suite.
I guess my motto is that friends shouldn’t let friends program
without tests.