views:

3698

answers:

15

Could you recommend a testing tool/framework to use for testing C++ code in a UNIX environment?

+9  A: 

I use boost unittest framework at work. Lots of interesting capabilities like exception catching, and very very easy to use, I recommand. (look at boost unittest)

Steve Gury
Yeah, I used to use Boost Test, but then one day I had an issue with the testing framework not liking my ostream operator... after a few hours of struggling with it (and it not working), I tried UnitTest++ and it worked on the first go without issues. I use UnitTest++ now.
ceretullis
A: 

We use CppUnit at work; our platform is Windows, although I don't think that would make a difference here. It seems to do a pretty decent job. I don't have any experience with other unit testing frameworks, though, so I can't really give you a fair comparison.

Matt Dillard
A: 

EDIT: Ooops, I totally missed the 'UNIX' part if the question. But I'll leave this answer here, rather than delete it, because it still could be useful for people wanting C++ unit testing on Windows.


I use NUnit, I just write all my tests in C++/CLI and then reference the same native C++ libs that my main project does. You do need to make a 'stub' .exe project that does almost nothing other than call the startup code in the .lib for this to work though.

It might seem a bit odd doing it this way, but I've found the testing tools for .NET to be miles ahead of C++ (e.g. NUnit), and C++/CLI is pretty good now. It also makes it easier to link your unit tests into CruiseControl.NET.

Obviously none of this is any of use if you're not developing with Visual Studio, in which case I'd probably go for Boost's test framework as well.

Wilka
+13  A: 

Not specific to UNIX, but there is a very detailed journal by Noel Llopis in 2004, where he explored several of the major unit testing frameworks of the time. Note that while at the end of the article he declares a winner (CxxTest), he has a follow-up post where he retracts his winner and instead starts writing his own unit testing framework, which turns into UnitTest++. At work we use a customized version of CppUnitLite, however I've been playing with UnitTest++ and it fixed some of the major shortcomings of CppUnitLite (catches exceptions in tests, implements test suites, built-in support for time limits).

Joe Schneider
+8  A: 

I use UnitTest++. For starters it will work with any C++ you care to mention including (with a bit of hacking) VC6. It comes with solutions for VS2002-2005 and make files for posix environs.

It also works well with AMOP - a mock object framework.

Update: And now it shouldn't need any hacking to work with VC6 - the hacks are included with the source!

graham.reeds
+4  A: 

I once did a comprehensive test of (if I remember correctly) five unittest-frameworks for C++, but not specifically for a UNIX environment. There where two clear winners for me, being CPPUnit and UnitTest++. Back then CPPUnit was the best choice since (imo) setting up a testing-project is way easier than with UnitTest++ but at work I use UnitTest++ these days.

Sadly, I haven't been able to find the document since the original posting date of this comment. If I ever find the document again (It's there, somewhere in a backup I suppose) I'll post the comparison below.

Idimba found this good article summarizing a lot of the pros / cons of different C++ test frameworks.

Huppie
+2  A: 
Clayton
+2  A: 

We use UnitTest++ here for our new project, and generally get along very well with it. We need it to be multi-platfom, including Mac.

Choosing the framework is just half the battle. Working out how you organise test code and hook it into a cross-platform build environment is the next step. The biggest challenge is educating your engineers to effectively use unit testing - getting there, but by no means a solved problem. I'll be browsing SO for hints!

Under each of our module folders we have a unittest folder - always called that - which contains source files that obey a naming convention so they can be always built. The resulting EXE's go into a platform/build specific BIN folder where all the normal product DLL's end up. Our autobuild fails if there are no tests for the module.

Greg Whitfield
+2  A: 

I strongly recommend cxxtest, but regardless of the testing framework you choose, amop is a great addition.

On Freund
+3  A: 

We are using TUT. I strongly recommend it.

It is really easy to integrate into an application (just include the header file, which the only file : no lib), and writing tests is very easy because of the clever use of templates ! No macros or anything like that with TUT !

We are very happy with it !

Jérôme
I like the template<> template<>. We ended up wrapping macros around asserts, because you really want to know at which \_\_LINE\_\_ your test failed. Apart from that, great design.
Eddy Pronk
+4  A: 

You should also check out the latest google test toolkit for c++ googletest I have not tried it myself, but they say its got more features than CppUnit (or any other c++ unit testing framework). I am sure its very easy to learn the API since its based on other popular xUnit (like JUnit) framework

A: 

Just wanted to chime in to agree with Amit: gunit aka googletest is an excellent testing framework, and the code is an interesting read as well. (Especially the mock support!)

0124816
A: 

You might find the Aeryn testing framework worth a look

David Sykes
A: 

See also the answers to the closely related question "Unit testing for C++ code - Tools and methodology", here

TonJ
A: 

The tide is changing in the C++ unit test world. More details in my latest blog post - and things are still in flux, but several people converging on some new ideas.

Phil Nash