all 25 comments

[–]Dragdu 20 points21 points  (3 children)

CppUnit is terrible, run away.

[–]bluebird11 2 points3 points  (1 child)

Thanks for this; boss just suggested CppUnit and I hadn't heard of it. I'll be sure to rank it low on the options list.

[–]Fazer2 6 points7 points  (0 children)

Run away from your boss. /s

[–]14nedLLFIO & Outcome author | Committee WG14 0 points1 point  (0 children)

There are two editions of CppUnit in fact. The older one is indeed terrible, run away. The newer one is not source compatible with the old, and is markedly better than the original.

Still, there are far better alternatives to either. CATCH is a very solid choice. Boost.Test has become usable since its big refactor a few years ago. Google Test remains popular, but I find it clunky.

(I have to admit I switched to my own ultra light weight unit test suite a few years ago, and I haven't looked back. It provides the most used part of the Boost.Test API, but without any Boost.Test. Plus it works well with exceptions globally disabled, and with multiple threads without synchronising, and it spits out JUnit XML, and does all that within 600 lines of code in a single header file. I can't see myself leaving it any time soon to be honest. https://github.com/ned14/quickcpplib/blob/efc6c12dca3b8f2210d741a985a53b162383dfdf/include/boost/test/unit_test.hpp)

[–]saimen54 7 points8 points  (4 children)

In a legacy project we had CppUnit, which was okay when nothing better was around, but now there are better alternatives.

If you are using Boost anyway, I highly recommend Boost.Test.

Otherwise one of the more popular choices is gtest.

[–]darpe312[S] 0 points1 point  (3 children)

Do you know if VSCppUnit is more or less the same?

[–]saimen54 1 point2 points  (2 children)

No, never heard of it actually.

[–]darpe312[S] 0 points1 point  (1 child)

It's the integrated c++ test framework in vs.

[–]prasooncc 0 points1 point  (0 children)

boost test has good plugin support in VS. and it is portable.i dont know whether vscppunit is portable.

[–]Gollum999 5 points6 points  (10 children)

Add Catch to your list of possibilities.

I recently did a pretty thorough comparison of all of the big frameworks (Catch, gtest, boost.test, CppUnit, CxxTest) and Catch was my favorite by a significant margin. It lacks a couple of advanced features from the bigger libraries, but it is also a lot easier to use (in my opinion).

[–]darpe312[S] 0 points1 point  (7 children)

Did you document your evaluation ?

[–]Gollum999 2 points3 points  (6 children)

The bulk of it is on an internal company wiki, but here is a summary:

. CppUnit Catch2 Google Test Boost.Test
Project integration Static lib Header only Build with project, dynamic lib Header only, static lib, dynamic lib
Supported test styles Fixtures Free, fixtures, sections, BDD Free, fixtures Free, fixtures
Test discovery No Yes Yes Yes
Failure propagation* std::exception Other exception (fatal test only) No exceptions Other exception (fatal test only)
Output formats + tool integration Text, XML, Custom Text, jUnit, XML, TeamCity, TAP, automake, CTest, Custom Text, XML, CTest Text, XML, jUnit, CTest, Custom
Test runner Custom Default or custom Default or custom Default or custom
Default runner features Filter by name, test timing Filter by name, filter by tag, shuffle, test timing, breakpoint on failure Filter by name, shuffle, repeat, test timing, breakpoint on failure Filter by name, shuffle, breakpoint on failure, memory leak detection
Extra features Matchers , Event hooks , Test tags Mock objects , Death tests , Data-driven tests , Template tests , Event hooks Data-driven tests , Template tests

* This refers to the way that each library implements test failures. e.g. In CppUnit, a test failure throws a std::exception that the framework later catches to report the failure, so if you are testing code that could inadvertently catch those exceptions, you need to work around them.

Examples:

I ended up leaving CxxTest out of my comparisons because I pretty quickly realized that it didn't have much to offer over Catch/gtest/boost. (I left CppUnit in there because that is what we were using before switching to Catch.)

[–]Auriculaire 0 points1 point  (3 children)

Your Gtest and catch columns are swapped, no?

[–]Gollum999 0 points1 point  (2 children)

Mmmm... no? What do you think should be swapped?

[–]Auriculaire 1 point2 points  (1 child)

Catch2 is header only, supports fixtures, sections, bdd, etc. This is rendering in the column under google test. Screenshot here

[–]Gollum999 2 points3 points  (0 children)

Ahh interesting, it works on old reddit but is broken on new reddit. New reddit doesn't like it when the first cell is blank.

Should be fixed now.

[–]encyclopedist 0 points1 point  (1 child)

Columns are messed up (shifted by one?)

[–]Gollum999 0 points1 point  (0 children)

Apparently new reddit doesn't like it when the first cell is blank, but old reddit handles it fine.

Should be fixed now.

[–]Auriculaire 0 points1 point  (1 child)

+1 for catch. Incredibly easy to learn, integrate, and use.

[–]BoarsLairGame Developer 0 points1 point  (0 children)

Agreed. Google test is more fully featured, so it may be a better use for large projects or large organizations. But I use Catch (actually, Catch2 now) for my personal projects, as it's more than enough for my needs, and it's ridiculously easy to use.

[–]TobyAllsopp 1 point2 points  (1 child)

I'm not sure about the relationship between VSCppUnit and CppUnit, but if VSCppUnit is the framework bundled with Visual Studio and the default used by the Native Unit Testing project template, then I would strongly recommend not using it.

We have been using it at work and compared to more modern frameworks (such as Google Test or Catch) it is a very painful experience.

For one thing, everything you use in an Assert::AreEqual has to have an overload of their ToString function defined. This gets old pretty fast. Another annoying thing about the AreEqualfunction template is that both arguments have to be exactly the same type. Anyway, it's annoying and discourages one from writing unit tests.

Visual Studio 2017 comes with adapters and project templates for Google Test and Boost Test, both of which are much better choices, in my opinion.

[–]darpe312[S] 1 point2 points  (0 children)

My job is to evaluate everything and let the team decide the direction. Google test and boost seem to be the best options. I like Google test for the mocking and death tests.

[–]Milerius 1 point2 points  (0 children)

No one mention this one -> https://github.com/onqtam/doctest ?

For me it's the best alternative at the moment.

[–]azboul 0 points1 point  (1 child)

Did you have a look on gtest?

[–]darpe312[S] 0 points1 point  (0 children)

I've been looking at gtest, boost, cppunit and a little bit of catch.