Tutorial :Unit testing in C++



Question:

I've been reading a lot about Unit tests and Test Driven developemnt.

Recently, I also read java unit test code.

I however, prefer to develop in Qt. So I googled up "unit testing in c++" and found a host of information about various unit testing frameworks available for C++.

However, I could not find a reliable comparison of the the various frameworks.

So I look to the SO community to guide me through the selection of what may the "best" unit testing framework for c++.

Also, if anybody had specific comments regarding TDD in Qt (especially using Qt-Creator), then they are more than welcome.


Solution:1

Usually use Boost, but if you are using Qt, their QtTestLib might be the better choice.


Solution:2

I would recommend doctest (created by me) - it's the lightest on compile times from all the popular testing frameworks. It is also a direct competitor to Catch which is currently the most used framework - checkout the differences in the FAQ


Solution:3

This seems too be the same question as:

Unit testing in C++ which is actually c++ despite the URL title.

From there, they link to two more SO questions which should help:

Unit testing for C++ code - Tools and methodology C++ unit testing framework


Solution:4

The "xUnit" family of testing frameworks is usually pretty solid (jUnit, NUnit, etc.). I haven't used it myself, but there is a port of jUnit for C++:

http://sourceforge.net/projects/cppunit


Solution:5

There is a table comparing all (?) the C++ unit test frameworks available from wikipedia.

There also is an old comparison of C++ unit test frameworks available. I do not think it has not been updated so I mention it as a complement as it's more argumented than the table. It covers, CppUnit, CppUnitLite, Boost.Test, NanoCppUnit, Unit++, CxxTest, especially it does not cover Google C++ framework.


Solution:6

Boost is usually a good choice, and it contains a testing framework, the Boost Test Library. I have used it for small test cases and it did what I expected, but I haven't used it extensively like in TTD.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »