Unit Testing, Agile Development, Leadership & .NET - By Roy Osherove
Google Test ( code.google.com/.../googletest ). It does not handle exceptions terribly well out of the box, but it is easy to patch it for that. Except for that, it is as close to the rest of the xUnit-experience as you are likely to get in C++.
boost/test with one file defining the module and including <boost/test/included/unit_test.hpp> and all others doing:
That let's you have an pure-header testing framework with automatically registered test cases and proper exception support.
I looked at google test (didn't quite look mature yet; required building standalone library for which I'd have to write my own makefiles, exception handling support looked iffy).
Using boost/test with a standalone lib is also a hassle; it probably has faster build times but has the downside that if you support a bunch of platforms or build options then you may need a lots of different lib builds; and that makes installing a new workstation a hassle and portability a hassle in general.
I used google mocking gmock and hippomocks. I definitely prefer hippomocks because you don't have to maintain seperate definitions for mocks. Mock creation is fast and easy but uses strict style.
Why don't you like CppUnit? My team tried CxxTest but the way their isolation framework works imposes the use of the T:: namespace on production code, which is gross.
I'm working on it - will let you know when it's ready:
- that is unless Kevlin Henney releases his first ;-)
I'm using CppUnit. It's not great, but what is? CppUTest is easier to use, but not that much easier. With a few vim macros to ease the pain, CppUnit is fine.
We are using GoogleTest and GoogleMock.
If you are coming from an environment with strong testing and mocking tools, like C# or Java, it is going to be a little painful.
Still I am glad that these tools exist because developing C++ code without TDD is more painful. Here are some of my observations
I use www.visualassert.com/unit-testing-framework
It works pretty well. Based on cfix. Give it a try.
Visual Studio-only though.
We use NUnit. Instead of writing test classes in C#, we write them in C++/CLI and apply the usual [TestFixture] attribute. Test methods in the C++/CLI test classes call the native C++ code and it works.
All we have to do is tweak the Visual Studio configuration so that the code under test gets built as a static library.
Our project at work contains a mix of native and managed code so it's nice to be able to run all tests in one go from the NUnit GUI runner regardless of whether the code under test is C++ or C#.