Unit Testing in C++ is harder than..

My blog has moved. You can view this post at the following address: http://www.osherove.com/blog/2010/9/6/unit-testing-in-c-is-harder-than.html
Published Monday, September 06, 2010 10:45 AM by RoyOsherove
Filed under:

Comments

Monday, September 06, 2010 11:21 AM by Rasmus Faber

# re: Unit Testing in C++ is harder than..

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++.

Monday, September 06, 2010 11:53 AM by Eamon Nerbonne

# re: Unit Testing in C++ is harder than..

boost/test with one file defining the module and including  <boost/test/included/unit_test.hpp> and all others doing:

#define BOOST_TEST_INCLUDED

#include <boost/test/unit_test.hpp>

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.

Monday, September 06, 2010 12:43 PM by Daniel marbach

# re: Unit Testing in C++ is harder than..

Hello

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.

Daniel

Monday, September 06, 2010 1:14 PM by Matt Baker

# re: Unit Testing in C++ is harder than..

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.

Monday, September 06, 2010 1:44 PM by Phil Nash

# re: Unit Testing in C++ is harder than..

I'm working on it - will let you know when it's ready:

www.levelofindirection.com/.../the-ultimate-c-unit-test-framework.html

- that is unless Kevlin Henney releases his first ;-)

Monday, September 06, 2010 3:14 PM by bob

# re: Unit Testing in C++ is harder than..

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.

Monday, September 06, 2010 8:51 PM by Michael Denomy

# re: Unit Testing in C++ is harder than..

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

mdenomy.wordpress.com/.../tdd-with-cpp

Tuesday, September 07, 2010 1:55 PM by googly

# re: Unit Testing in C++ is harder than..

I use www.visualassert.com/unit-testing-framework

It works pretty well. Based on cfix. Give it a try.

Visual Studio-only though.

Saturday, September 11, 2010 5:54 AM by Matt

# re: Unit Testing in C++ is harder than..

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.

www.codinginlondon.com/.../using-nunit-with-native-c.html

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#.