If You Don't Unit Test Your Code, You're A Bloody Idiot!

by Glenn Fiedler on January 12, 2009

I’ve been pretty big on unit tests for a long time now, but for some reason (maybe I’m mildly retarded?), I’ve always used my own homespun CHECK macro to code unit tests, something like this:


#define CHECK( condition ) do { if ( !(condition) ) { exit(1); } } while(0)

I switched some tests over to UnitTest++ last weekend, and I can’t believe I left it so long, UnitTest++ is great!

What can I say, it took about a minute to integrate it into my project, then a few hours to convert my tests over – everything worked first time. It’s simple and clean, and I can easily run my tests as part of my build process so I *have* to fix the tests whenever they fail before my game runs.

I’m not even using any of it’s more advanced features. Just using CHECK, SUITE and TEST, and the occasional TEST_FIXTURE when needed.

So if you have your own shitty ASSERT or CHECK macro based tests, switch over now! And if you aren’t using unit tests in your code, what the hell are you fucking insane?!! I hope you enjoy debugging because ya gonna be doing a lot of it! :)

Do yourself a favor and check it out if you haven’t already:

http://unittest-cpp.sourceforge.net/UnitTest++.html

{ 6 comments… read them below or add one }

nllopis January 13, 2009 at 9:34 am

Glad you liked it so much! I do, but I’m biased :-)

Reply

Glenn Fiedler January 13, 2009 at 11:18 am

yeah jim has been poking me to switch over to UnitTest++ – he was right! :)

Reply

Charles January 13, 2009 at 10:22 am

Haha thanks for the kind words Glenn!

Reply

mattb January 16, 2009 at 2:34 pm

!!!!

I was looking into using the unit test framework presented in the TICPP book, but UnitTest++ has just stolen all the cookies.

So awesome.

Reply

Sam Jansen January 20, 2009 at 2:58 pm

The next step of the unit tester is often mock objects…

http://code.google.com/p/googlemock/

Unfortunately Google Mock requires Google Test (though Google Test looks quite similar to UnitTest++ I have to say).

Reply

Tatou May 6, 2010 at 6:45 am

http://code.google.com/p/amop/

A good mock libaray which can be used with UnitTest++

Reply

Leave a Comment

Previous post:

Next post: