Monday, March 7, 2011

Unit testing in C++

How do I get started doing unit testing in C++ ?

I have used Junit when coding in Java and found it very useful. Is there something similar in C++ ? What do you recommend ?

From stackoverflow
  • Check CppUnit, it's the jUnit port to C++.

  • Without knowing which platform/compiler you are targetting, I can only make a general recommendation. I've used this (CppTest) one quite successfully in the past. There's a simple framework called UnitTest++ that looks interesting.

  • Good round up here.

    We use Boost.Test, and we are able to do good cross platform continuous integration.

  • Take a look at this page: http://gamesfromwithin.com/?p=29

    It is the best comparison of the C++ frameworks. I personally prefer Boost.Test.

  • Here are similar questions that you may want to look at:

    I recommend you check out Google's unit testing framework in addition to CppUnit.

  • My personal favorite is TUT. The two main reasons are that 1) it doesn't force Java-isms on you but takes advantage of what C++ is, and 2) you have control over it, writing the executable (I have a template I used), the reporting etc (provides a stream based version by default).

    To me it very much follows the philosophy of KISS, 2 headers, no macros, no parsers, just plain old C++ code with a tiny bit of skeleton code.

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

  • UnitTest++, legend has it that UnitTest++ was written by the author of this comparison of unit testing frameworks.

  • I haven't been happy with any C++ unit testing framework. Since C++ doesn't have reflection, it's hard to write convenient unit testing tools. CxxTest is about as good as I've found. I've used it on some projects, but usually I just write my own tests either without a framework or using a crude framework I wrote myself.

  • Aeryn is another C++ Testing Framework worth looking at

  • I just started using googletest (http://code.google.com/p/googletest/). Its simple to integrate and I haven't had any problems with it.

  • Have a look at CUnitWin32. It includes an example.

  • I recently wrote a 5-part series of blog posts covering unit testing in C++ with boost. It gives step by step instructions for how to do this in Visual Studio.

    • Part 1: how to start making unit tests in C++ with Boost.Test.

    • Part 2: the assertion framework provided by Boost.Test in the context of a simple programming exercise that demonstrates test-driven development.

    • Part 3: continuing with test-driven development to complete the functionality of the PrimeFactors::Generate method.

    • Part 4: test-driven UI development.

    • Part 5: the facilities in Boost.Test for sharing common setup and teardown actions between tests and organizing tests into suites.

0 comments:

Post a Comment