views:

304

answers:

8

I'm looking into some possible options for unit testing C++ classes.

So, short and to the point, what are you using?

+4  A: 

I'm using cppunit. It is a pretty good port of the iconic JUnit to c++.

David Arno
The stable version of cppunit lacks many assertions, and requires a lot of hand written and redundant code that frameworks like cxxtest or fructose are able to infer automatically (thanks to external scripts actually). cppunit may be a port of a good Java framework, but it missed C++.
Luc Hermitte
+2  A: 

UnitTest++. In the past I used Boost Test, which is also pretty good, but I ran across a problem where boost test wanted an operator<< defined and it wouldn't accept my overloaded operator<<. UnitTest++ didn't flinch a bit.

ceretullis
+2  A: 

I'm using Google Test

John Dibling
+2  A: 

CxxTest, which runs a Perl script as a preprocessor to detect all methods named test*. It's pretty easy to work with, since Perl does all the suite/case registration for you.

Ben Straub
+1  A: 

This question has been asked and answered several times already. See stack overflow archives

Luc Hermitte
Searching for the topic and digging through the unit testing category yielded no matches. Related questions doesn't show any matches, either.Apologies for the dupe, but finding information isn't as easy as it should be.
Gabriel Isenberg
Try the link I gave -> It restricts the search to test-units and C++
Luc Hermitte
A: 

Simple console applications that link the lib / DLL, and use assert statements.

It fits my main requirements: easy to set up, and when an error occurs you can immediately break into the debugger.

To run an individual test repeatedly, the call to the routine is (temporary) copied to the top.

It has some shortcomings, though: First, you don't have an automatic visual verification which tests did run, but that can be fixed with a print statement. You don't get a list of tests that failed. Beyond that, compared to any environment supporting reflection, the added value of unit test frameworks seems a bit low to me. And better these than no unit tests at all.

peterchen
+2  A: 

Boost.Test. I use boost anyway, might as well use its test library as well rather than yet another different library.

KTC
I used to agree with you... one day I spent 4 or 5 hours trying to get Boost Test to take an overloaded ostream operator, after which I thought maybe I'll try another testing framework just to see... UnitTest++ didn't complain a bit.
ceretullis
A: 

Have a look at CUnitWin32. It includes an example.

Dushara