Announcing: New Google C++ Testing Framework
Thursday, July 03, 2008
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 googletestframework@googlegroups.com (the Google Test Discussion Group). See you there!
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?
ReplyDeleteBtw, I had to apply the following patch to make it compile for me:
ReplyDeletehttp://el-tramo.be/files/gtest/gtest-1.0.0-includeinternal.patch
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.
ReplyDeleteI was able compile it without modifications on Ubuntu, though.
I too am curious about why anyone would choose this over boost::test...
ReplyDeleteDeath 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:
ReplyDeleteEXPECT_DEATH(MyFunction(bad_input));
Not sure if any other unit testing frameworks support that.
Am I the only one that is bothered by names of things & what one must type to use this?
ReplyDeleteEXPECT_DEATH(...)
should actually be a fatal assertion, and a non-fatal one should be:
EXPECT_LIFE_AFTER_DEATH(...)
There, now it seems right.
Oops, my example was wrong. It's actually:
ReplyDeleteEXPECT_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.
kenton wrote:
ReplyDelete>> 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++ http://unittest-cpp.sourceforge.net/
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.
Doh, I guess I need to write better tests for my humor detector. ;)
ReplyDeleteHi, I created a new website and expecting your comments on it.
ReplyDeletehttp://www.prog2impress.com/index.html
The google test primer link appears to be misdirected. It should direct to : http://code.google.com/p/googletest/wiki/Primer
ReplyDelete