Jun 202015

I have been using a library called libunittest for unit testing an open source project. A couple months ago I did a feature request for it, namely for an assertion for relative approximation. It’s an incredibly easy library to use and comes with a lot of documentation. Here is one of the examples which shows the “easy” way where you don’t have to register the test class:

After installing, link against it and compile, then execute:

This example and others are covered in the tutorial provided on the website: http://libunittest.sourceforge.net/tutorial.html

I personally like a different style that libunittest supports which is a bit more writing of code but I believe it’s a nice way of organizing a test suite:

For learning about the other types of assertions you can do, you may want to peruse the testing code:


Happy testing!

  2 Responses to “libunittest: a portable C++ library for unit testing”

  1. Hi Brock, I also enjoy using libunittest for my C++ projects. Have you considered using the assertion macros that libunittest provides? Aside from less typing, they provide you with the call site signature in case of an assertion failure.

    • Hi Christian,

      I’m assuming you are referring to UNITTEST_ASSERT_EQUAL and their associated shortcuts e.g., ASSERT_EQUAL. Someone at my office recently said the same thing! After considering it, it seems appropriate to make the switch 😉 Googletest also uses assertion macros apparently e.g. http://code.google.com/p/googletest/source/browse/trunk/samples/sample1_unittest.cc But don’t worry, I’m a loyal libunittest supporter 🙂

      I’ve updated the example with an assertion failure to demonstrate the call site signature. Thanks for the comment!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">