Sign in to follow this  
Thorris

C++ unit tests

Recommended Posts

Hello, does anyone know a good framework for unit tests in C++. I know NUnit, but I think it is only for managed languages in .NET. Ciao, Thorris.

Share this post


Link to post
Share on other sites
Check out cppunit. I've used it for a few projects. It's a little primitive in some regards (eg. doesn't have the robust collection of libraries available that JUnit has), but it's effective and easy to use.

Share this post


Link to post
Share on other sites
I'd second the use of CPPUNIT, we useit for automated builds as well as post compile chekcing on the dev systems.

We also use it ON OS X wihtout changing any source code.

Cheers
Chris

Share this post


Link to post
Share on other sites
I've never understood why people seem to think they need some sort of framework to make unit tests. I find they just get in the way and make debugging failed tests harder.

For me an ideal unit test has these features:

Small - I can throw it on a floppy if I have to.
No installation - if I have to do anything other than xcopy something is wrong.
One file - Fewer files to keep track of is good.
Little overhead code - I don't want to have to step through 1000 lines of boilerplate/framework code to get at the problem.
No special environment - I don't want to have to remember to set environment variables, make sure some logging server is just so, etc.

etc. Basically what it comes down to is that the more effort it takes to run the test (and interpret the results) the less likely devs are going to actually run them.

Share this post


Link to post
Share on other sites
We've never had a problem with the framwork, its small, lightweight and it does all sorts of formatting, automatically exports the results to xml and outputs them in the debugger window. None of these come for free if you write your own.

But some people still have the not inveted here syndrome. If someone has a problem with CPPUNIT I'd love to hear it:)

CHeers
Chris

Share this post


Link to post
Share on other sites
I found a framework called tut. It is based on templates so the compiler needs to have good support for them. I have used it at my job and it works fairly well. There is some code you have to provide to format the output, but nothing major. Just an alternative to cppunit. Not that it is bad nor is this one better. Just different approaches to the same problem.

http://tut-framework.sourceforge.net/

Chris

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this