Announcing: New Google C++ Testing Framework
According to Google the primary highlights of this release are:
- 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.
We hope this list can help you decide whether [Google Test is useful] for you too:Saptarshi "Sunny" Purkayastha spent some time checking the new framework out and posted his initial thoughts on his blog. His reaction was positive:
- Google Test is designed to be portable. It works where many STL types (e.g. std::string and std::vector) don't compile. It doesn't require exceptions or RTTI. As a result, it runs on Linux, Mac OS X, Windows and several embedded operating systems.
- Nonfatal assertions (EXPECT_*) have proven to be great time savers, as they allow a test to report multiple failures in a single edit-compile-test cycle.
- It's easy to write assertions that generate informative messages: you just use the stream syntax to append any additional information, e.g. ASSERT_EQ(5, Foo(i)) << " where i = " << i;. It doesn't require a new set of macros or special functions.
- Google Test automatically detects your tests and doesn't require you to enumerate them in order to run them.
- No framework can anticipate all your needs, so Google Test provides EXPECT_PRED* to make it easy to extend your assertion vocabulary. For a nicer syntax, you can define your own assertion macros trivially in terms of EXPECT_PRED*.
- Death tests are pretty handy for ensuring that your asserts in production code are triggered by the right conditions.
- SCOPED_TRACE helps you understand the context of an assertion failure when it comes from inside a sub-routine or loop.
- You can decide which tests to run using name patterns. This saves time when you want to quickly reproduce a test failure.
Another excellent thing about the framework was that it’s easy to learn the basics as well has advanced features. Its very similar to xUnit tests and has good features to compare with CppUnit. The basics can be learnt from here and the advanced guide is here. Predicate Assertions are probably one of my favorite features, that we encountered quickly in a program that we were having trouble to debug. There are also a host of other assertions available and we’ve not got into very deep with all the assertions. But from the initial look at the framework, most of us very ranking it as one of the best testing frameworks out there...According to the wiki, you can get up and running with Google Test by checking out their Primer, and then referencing the Advanced Guide for more intensive use.
Download the framework here, try it out, and let the community know what you think!
Mike Amundsen May 29, 2015
Ben Linders May 28, 2015