Thursday, July 03, 2008

Announcing: New Google C++ Testing Framework

We all know the importance of writing automated tests to cover our code. To make it easier for everyone to write good C++ tests, today we have open-sourced Google C++ Testing Framework (Google Test for short), a library that thousands of Googlers have been using in our C++ programs. Highlights of the project include:
  • Google Test is portable: it works on a variety of platforms (Linux, Windows, Mac OS X, and more), with several versions of GCC and MSVC compilers, and with or without exceptions. You can even use it in embedded systems like Windows CE and Symbian. Build tools and test runners for many of these are under active development, with Linux Autotools support already in place.
  • It supports both fatal and nonfatal assertions. The test will continue after a nonfatal failure. This allows more problems to be uncovered and fixed in a single edit-compile-test cycle.
  • It provides many assertions for common testing needs, and lets you easily define new assertions for less common cases.
  • On Linux, you can write death tests to ensure that your code crashes with expected errors.
  • Because it's based on the popular xUnit architecture, Google Test is easy to learn if you've used any testing framework in this family before.

It will take you about 10 minutes to learn the basics and get started. Stay tuned to this blog for helpful Google Test information in upcoming Testing on the Toilet episodes.

Please send questions and feedback to (the Google Test Discussion Group). See you there!


  1. On first sight, it seems that Google Test doesn't provide much over CppUnit. However, when I look a bit deeper into the advanced part of the manual, I'm finding interesting new things. Maybe it would be good to have a list of features why one would choose Google Test over CppUnit?

  2. Btw, I had to apply the following patch to make it compile for me:

  3. I am with remko about a list of features that puts this testing framework apart from others, like CppUnit or Boost's Unit Test Framework.

    I was able compile it without modifications on Ubuntu, though.

  4. I too am curious about why anyone would choose this over boost::test...

  5. Death tests are a pretty cool feature, though currently only available on Linux. They let you verify that your asserts trigger when they're supposed to. The syntax is really simple, too:


    Not sure if any other unit testing frameworks support that.

  6. Am I the only one that is bothered by names of things & what one must type to use this?


    should actually be a fatal assertion, and a non-fatal one should be:


    There, now it seems right.

  7. Oops, my example was wrong. It's actually:

    EXPECT_DEATH(MyFunction(bad_input),"expected error message");

    maksa: not sure what you mean. Note that EXPECT_DEATH (and ASSERT_DEATH) executes the crashing code in a sub-process, which allows the unit test to continue running after the crash.

  8. kenton wrote:
    >> maksa: not sure what you mean

    Pay no mind, it was just an attempt at a (probably bad) joke, with no pretensions on some technical merit whatsoever.

    It is really fine that Google released this, so far my choice has been UnitTest++
    It's a bit troubling that this Google thing is yet another C++ unit testing framework, albeit it seems to be the most powerfull so far - if I had a greenfield project I'd most probably go for it. The other (real) problem is how to convnice more people to do unit testing. Still waiting for some magic in that area, and if any of you actively blogging people managed to successfully introduce TDD/UT in his work environment (by "successfully introduce" I don't mean "nobody killed you for writing unit tests"), please don't be shy to write about your experience.

  9. Doh, I guess I need to write better tests for my humor detector. ;)

  10. Hi, I created a new website and expecting your comments on it.

  11. The google test primer link appears to be misdirected. It should direct to :


The comments you read and contribute here belong only to the person who posted them. We reserve the right to remove off-topic comments.