GoogleTest vs CppUnit: The facts
Asked Answered
B

3

74

In the process of setting our C++ unit testing framework for the next years we shortlisted GoogleTest and CppUnit. I have some experience with both and my heavy preference is GoogleTest. Anyways to convince my boss I need some facts so I did some reading on the Internet, including the manuals, wiki pages and some of the sources. I came up with a list of GoogleTest advantages and a single CppUnit advantage(graphic test runners). Here they are ordered by perceived usefulness:

  • INSTANTIATE_TEST_CASE_P to instantiate a test case with any set of parameters you want, including Cartesian products
  • FRIEND_TEST for testing private class members(for all the legacy code)
  • turning asserts into breakpoints
  • non-fatal asserts
  • "out of the box" googlemock integration
  • automatic tests detection, no need to enumerate them
  • tests can be disabled and enabled
  • tests to run can be selected using name patterns
  • value/type-parameterized tests
  • user-defined predicate asserts
  • death tests
  • much richer set of asserts
  • type asserts
  • asserting on subroutines
  • additional debug info can be added to asserts using <<
  • RecordProperty emits last value of property to the XML output
  • SCOPED_TRACE helps understand the context of an assertion failure coming from inside a sub-routine or loop.
  • xUnit XML output, can be shown by Jenkins right away without a XSLT transformation in between
  • supports custom types printers
  • time consumed by test indication(I suspect this is also possible with CppUnit but I haven figured it out yet)
  • test event listener API (user-defined plug-ins)
  • test shuffling
  • no exceptions and RTTI

Am I correct in assuming that all of the above are not supported by CppUnit? Is there an useful GoogleTest feature not available in CppUnit I am missing?

And last but not least: Are there any nice CppUnit features that GoogleTest lacks?

Thanks!

Bagley answered 27/10, 2011 at 20:55 Comment(3)
Some of the answers to Comparison of c++ unit test frameworks specifically address GoogleTest features.Umbrage
A couple of years ago I was doing a similar survey, GoogleTest was not around then. I settled on CXXTest which had a mechanism to enumerate the test cases by a pre-parsing step with Perl. That was vastly superior to CppTest. That said, I know nothing about GoogleTest.Trevortrevorr
A graphic test runner is an advantage? Usually you want something that can be automated easily, because automation means you get test feedback more easily and more often.Mantling
P
7

If you use older version of gcc compiler or if your code under tests runs on vxWorks (or VxSim) you might have a better chance with cppUnit than Googletest framework.

On the other hand, another feature of the googletest framework is availability of 3 different levels of setup/teardown:

  • per program
  • per test case (or test group)
  • per individual test instances

Not sure if this is supported in cppUnit, but this might come very handy, especially with legacy systems.

Also, there is a googletest plugin for Eclipse CDT.

Pouncey answered 3/11, 2011 at 8:2 Comment(0)
M
6

If you haven't looked at xUnit++, I made it specifically because I was unhappy with what was available (including gtest). Most of your list is supported, and if not, if it's a "must have" feature, I'd probably be willing to add it.

Maddy answered 25/10, 2012 at 5:0 Comment(5)
Can you release it under a permissive open source license? Like Apache 2.0 or MIT License?Outrider
I honestly don't remember which license is being used, but I think it's the MIT License.Maddy
Thank you so much, but although text is the same, License.txt doesn't say that it's the MIT License. Would you mind adding it (when you have time, of course), if it's okay? Like this opensource.org/licenses/MIT? I think it would allow more people use and try this wonderful framework :-)Outrider
The wikipedia page en.wikipedia.org/wiki/List_of_unit_testing_frameworks also doesn't say that xUnit++ is released under the MIT License, probably because it's not specified anywhere in your bitbucket repo (I think) :-)Outrider
dead link? smb got the github upload?Dropline
D
4

Those are the benefits I see. There are a couple of GUI test runners:

  1. https://github.com/ospector/gtest-gbar
  2. https://github.com/SandyChapman/gtest-runner-qt

I have used the first one and it works pretty well although it's in development and needs some work. Don't know if there are other options.

Divulgate answered 3/11, 2011 at 20:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.