views:

2816

answers:

6

I know there are already a few questions regarding recomendations for c++ unit test frameworks, but all the answers did not help as they just recomend one of the frameworks but do not provide any information about a (feature) comparison.

I think the most interesting frameworks are CppUnit, Boost and the new Google testing framework. Has anybody done any comparison yet?

+8  A: 

See this question for some discussion, and this question as well.

They recommend the articles: Exploring the C++ Unit Testing Framework Jungle, By Noel Llopis. And the more recent: C++ Test Unit Frameworks

I have not found an article that compares googletest to the other frameworks yet.

Sam Saffron
As I wrote: all the answers just recomend one of the frameworks but do not compare the framework to another.
housemaister
You're not happy with the article either ?
Gishu
One criticism: the article, while good, is from 2004 and doesn't include Google Test.
rq
I have to admit that I ignored the article as it is rather old; but I will make up for this now. Btw: better link to the article: http://gamesfromwithin.com/?p=29Nevertheless comparison to google test is of course missing.
housemaister
In the first link you'll see two comparisons. Except the new framework from google, most information is (are?) still relevant.(And CppUnit is not the most interesting, it's too clumsy to use)
Luc Hermitte
fixed up links and expanded the answer with a more recent comparison
Sam Saffron
+1  A: 

http://accu.org/index.php/journals/368

+3  A: 

Wikipedia has a comprehensive list of unit testing frameworks, with tables that identify features supported or not.

John Deters
+1  A: 

There are some relevant C++ unit testing resources at http://www.progweap.com/resources.html

Dave Young
+4  A: 

A new player is Google Test (also known as Google C++ Testing Framework) which is pretty nice though.

#include <gtest/gtest.h>

TEST(MyTestSuitName, MyTestCaseName) {
    int actual = 1;
    EXPECT_GT(actual, 0);
    EXPECT_EQ(1, actual) << "Should be equal to one";
}

Main features:

  • Portable
  • Fatal and non-fatal assertions
  • Easy assertions informative messages: ASSERT_EQ(5, Foo(i)) << " where i = " << i;
  • Google Test automatically detects your tests and doesn't require you to enumerate them in order to run them
  • Make it easy to extend your assertion vocabulary
  • Death tests (see advanced guide)
  • SCOPED_TRACE for subroutine loops
  • You can decide which tests to run
  • XML test report generation
  • Fixtures / Mock / Templates...
Wernight
I really enjoy using google test over some of the other frameworks especially with its mocking capabilities that can be found in the googlemock framework.
weijiajun
+4  A: 

Boost Test Library is a very good choice especially if you're already using Boost.

// TODO: Include your class to test here.
#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(MyTestCase)
{
    // To simplify this example test, let's suppose we'll test 'float'.
    // Some test are stupid, but all should pass.
    float x = 9.5f;

    BOOST_CHECK(x != 0.0f);
    BOOST_CHECK_EQUAL((int)x, 9);
    BOOST_CHECK_CLOSE(x, 9.5f, 0.0001f); // Checks differ no more then 0.0001%
}

It supports:

  • Automatic or manual tests registration
  • Many assertions
  • Automatic comparison of collections
  • Various output formats (including XML)
  • Fixtures / Templates...

PS: I wrote an article about it that may help you getting started: C++ Unit Testing Framework: A Boost Test Tutorial

Wernight