13

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.

demonplus
  • 5,613
  • 12
  • 49
  • 68
jrharshath
  • 25,975
  • 33
  • 97
  • 127

7 Answers7

18

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

stephan
  • 10,104
  • 1
  • 51
  • 64
  • just what I was looking for :) – jrharshath May 27 '09 at 06:00
  • I dont know about Boost so much but the biggest downside of QTestLib is that it isnt reliable with crashes - eg if your unit crashes, your whole suite crashes and then the report will be hard to parse (if you rely on that feature, for example in automatic test reporting). – rasjani Jun 08 '09 at 19:08
5

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

onqtam
  • 4,356
  • 2
  • 28
  • 50
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

Community
  • 1
  • 1
NoahD
  • 8,092
  • 4
  • 27
  • 28
3

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.

philant
  • 34,748
  • 11
  • 69
  • 112
  • 1
    Boost.Test at least has been heavily extended and improved since the gamesfromwithin article was written. The same is probably true for the other frameworks as well, but I don't use those, so can't say for sure. – jalf May 27 '09 at 14:08
2

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

Andy White
  • 86,444
  • 48
  • 176
  • 211
  • 2
    cppUnit is very easy to use and run - we use it in a commercial environment, testing over 50 separate Dlls, each with a few thousand test cases. It's proven to be very reliable and flexible. – Thomi May 27 '09 at 07:47
1

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.

sth
  • 222,467
  • 53
  • 283
  • 367
0

If you want to get off the ground quickly without figuring out how to build a library, there is a single header file include solution, which supports fixtures (setup and teardown), the usual TEST() {} with CHECK_TRUE, etc. It also has memory leak detection and performance testing capabilities.

https://gitlab.com/cppocl/unit_test_framework