Reputation: 43547
edit: This question might be vote-closed because "not a real programming question". To which I can only retort "nyah!" Now I did find this question which is directly related and should help.
I'm methodically upgrading my source code to get with the C++11 times, and one of the pieces that a lot of my code interacts with is UnitTest++.
I dedicate the latter half of every one of my implementation cpp
files to unit tests, so they include many
TEST(testname) {
// test code
}
declarations.
Now, UnitTest++ is about 8 years old and it still compiles great, so I have no urgent need to replace it. However I have found that it is probably no longer being maintained (though its existing features certainly seem solid enough, this is a bad sign) as the website and sourceforge are down.
So even though my code works fine now, it may benefit me now to switch to a better system earlier rather than later, because it will reduce translation burden in the future.
I looked around a bit and there seem to be a few options available to me. Particularly interesting is libunittest and others like CATCH which is header-only.
My question is for folks who have maybe had experience with UnitTest++ in the past and other unit testing systems, what has worked well for you and if you have any recommendations. I am looking for something that is extremely portable and which has zero external dependencies beyond a C++98/03 or C++11 compiler (gcc, clang, msvc) and the standard libraries, and where being header-only is a plus but not necessary.
So I guess my preferences do tend to narrow down the options quite a bit. Even with UnitTest++ I enjoy its portability and self-containedness, but I have had to write a good ~100 or so lines worth of code to extend it to be flexible for me in two ways:
A perfect answer would be something like this from none other than one of the guys behind UnitTest++ itself! But that article is 10 years old!!
Upvotes: 2
Views: 1129
Reputation: 25380
I have two more:
Both are actively developed.
that is extremely portable [...]
[...] beyond a C++98/03 or C++11 compiler (gcc, clang, msvc) and the standard libraries
CppUTest can be used with various compilers and platforms - it's used for embedded systems too. In addition at has a build in C interface.
and which has zero external dependencies
Not much to say: download / checkout and build, done.
and where being header-only is a plus but not necessary.
Unfortunately this is not possible with CppUtest, it requires it's testlibrary for linking.
allow me to specify specific tests to run
Possible and also explained in the manual (not very difficult). See here.
customize reporting behavior for tests such as showing me timing data per test and summarizing totals at the end
This is done per default in verbose mode. It's also possible to export JUnit Xml files with the result. In addition you can customize the output format for all steps and kinds of output.
Example code:
TEST_GROUP(FirstTestGroup)
{
/*
* Test group = test suite
* You can implement tear down / setup here too
*/
};
TEST(FirstTestGroup, FirstTest)
{
FAIL("Fail me!");
}
TEST(FirstTestGroup, SecondTest)
{
int value = 4;
const int expected = 4;
CHECK_EQUAL(expected, value);
}
Finaly it's not difficult to use: check the Manual.
Btw. it contains mocking (CppUMock) and an integrated memory leak detector.
Documentation:
Upvotes: 0
Reputation: 95629
You may find Google Test to be of use. It supports everything UnitTest++ does and more, and it is still maintained (and regularly used within Google). Additionally, it has a corresponding mocking library, Google Mock for creating mocks that is pretty useful for creating mock implementations.
Upvotes: 2