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,320
  • 11
  • 48
  • 64
jrharshath
  • 24,957
  • 33
  • 95
  • 127

7 Answers7

18

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

stephan
  • 9,794
  • 1
  • 49
  • 63
  • 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,208
  • 1
  • 27
  • 48
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
  • 7,672
  • 4
  • 24
  • 28
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
  • 84,168
  • 47
  • 173
  • 207
  • 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
2

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
  • 33,077
  • 11
  • 67
  • 110
  • 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
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
  • 211,504
  • 50
  • 270
  • 362
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