views:

512

answers:

10

We need to migrate a unit test harness developed with C# and NUnit to C++ running on Red Hat Linux.

We want to minimize the efforts in migration.

We are reading resources such as this:

http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle

But we don't see anything similar to NUnit.

+5  A: 

We use Google Mock and Google Test. Having never used NUnit, though, I can't comment on how similar it is to NUnit.

Grant Limberg
+6  A: 

Have You considered using CppUnit?

Here is an overview on unit testing frameworks for C++.

The Chairman
Yeah, I'm a little confused - cppunit is the first thing on that list you linked. cppunit and NUnit are both part of the xunit family (and both were originally ported from JUnit).
Jefromi
... so it should be a perfect match, shouldn't it? As far as I know CppUnit is the leading JUnit port for C++ (or at least one of them).
The Chairman
+5  A: 

And there's Boost.Test.

Max Lybbert
+1  A: 

I recommend you try UnitTest++:
http://unittest-cpp.sourceforge.net/UnitTest++.html

I don't know if it is similar to NUnit, but it is powerful, elegant, and simple-to-use.

Michael Aaron Safyan
+2  A: 

I use Boost.Test. I used to use CppUnit, but found that it works in a Java/Junit way as opposed to a C++ way. For example using setup and teardown methods instead of constructors and desctructors. Also the Test Case / Fixture support was a little laborious since C++ doesn't support reflection.

I found Boost.Test fitted better with the C++ code I was testing. It is also a lot more powerful. After a while I ported all my CppUnit tests to Boost.Test, this took about a day and I haven't looked back.

As far as I know the person behind cppunit also wrote cxxunit which is more C++esque.

iain
A: 

There is a good one called CPPUnit. It started its life as a port of JUnit to C++ by Michael Feathers. I have worked with it and it is great. Note though, that unit testing in C++ is harder than in other languages.

Seth Illgard
+1  A: 

Googletest is very similar in usage to xUnit. Googlemock is by far th best mocking framework for C++. The libraries are cross platform, have excellent documentation and an active user base. All you need is a compliant C++ compiler that can handle templates.

Michael Feathers, the original author of CppUnit, now recommends CppUnitLite, which is a bare bones framework. Once I have regaled him with the joys of Googlemock at ACCU 2010 I hope he'll embrace it :-)

Seb Rose
+3  A: 

You won't find anything very much like NUnit, unfortunately. Since C++ doesn't have the same strong reflection ability, the process for defining tests needs to be somewhat more explicit, rather than using attributes, as in NUnit.

I like cxxtest because it's easy to set up, and doesn't require manual test registration.

Mark Bessey
+1  A: 

There is a relatively new kid on the block called WinUnit. I haven't had time to try it myself but it might be worth a look.

Rob
A: 

Expanding on Mark Bessey's answer: I really like cxxTest because it's just a set of C++ header files & Perl scripts. As long as you have a C++ compiler & Perl, it will work on nearly any system. It also has features to integrate with your IDE (although I haven't used them).

Also, here's a good article Exploring the C++ Unit Testing Framework Jungle. This post is potentially out of date (circa 2004), but gives a great summary of features & straight-up examples utilizing each of the following C++ unit testing frameworks:

  • CppUnit
  • Boost.Test
  • CppUnitLite
  • NanoCppUnit
  • Unit++
  • CxxTest
Pete