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.
我知道已经有一些关于c++单元测试框架的recomendations的问题,但是所有的答案都没有帮助,因为它们只是重新组合了其中的一个框架,但是没有提供关于(特性)比较的任何信息。
I think the most interesting frameworks are CppUnit, Boost and the new Google testing framework. Has anybody done any comparison yet?
我认为最有趣的框架是CppUnit、Boost和新的谷歌测试框架。有人做过比较吗?
77
See this question for some discussion.
请参阅这个问题进行一些讨论。
They recommend the articles: Exploring the C++ Unit Testing Framework Jungle, By Noel Llopis. And the more recent: C++ Test Unit Frameworks
他们推荐这篇文章:探索由Noel Llopis开发的c++单元测试框架丛林。以及最近的:c++测试单元框架。
I have not found an article that compares googletest to the other frameworks yet.
我还没有找到一篇将googletest与其他框架进行比较的文章。
98
A new player is Google Test (also known as Google C++ Testing Framework) which is pretty nice though.
一个新的播放器是谷歌测试(也称为谷歌c++测试框架),这很好。
#include
TEST(MyTestSuitName, MyTestCaseName) {
int actual = 1;
EXPECT_GT(actual, 0);
EXPECT_EQ(1, actual) <<"Should be equal to one";
}
Main features:
主要特点:
ASSERT_EQ(5, Foo(i)) <<" where i = " <
SCOPED_TRACE
for subroutine loops91
I've just pushed my own framework, CATCH, out there. It's still under development but I believe it already surpasses most other frameworks. Different people have different criteria but I've tried to cover most ground without too many trade-offs. Take a look at my linked blog entry for a taster. My top five features are:
我刚刚推出了自己的框架。它还在开发中,但我相信它已经超越了大多数其他框架。不同的人有不同的标准,但我尽量不做太多的权衡。看一看我的链接博客文章。我的五大特点是:
It also has Objective-C bindings. The project is hosted on Github
它还有Objective-C绑定。该项目由Github托管。
45
Boost Test Library is a very good choice especially if you're already using Boost.
Boost测试库是一个非常好的选择,特别是如果您已经在使用Boost。
// TODO: Include your class to test here.
#define BOOST_TEST_MODULE MyTest
#include
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:
它支持:
PS: I wrote an article about it that may help you getting started: C++ Unit Testing Framework: A Boost Test Tutorial
PS:我写了一篇关于它的文章,可以帮助你入门:c++单元测试框架:Boost测试教程。
19
Wikipedia has a comprehensive list of unit testing frameworks, with tables that identify features supported or not.
Wikipedia拥有一个完整的单元测试框架列表,其中有一些表可以识别支持的或不支持的特性。
12
I've recently released xUnit++, specifically as an alternative to Google Test and the Boost Test Library (view the comparisons). If you're familiar with xUnit.Net, you're ready for xUnit++.
我最近发布了xUnit++,特别是作为谷歌测试和Boost测试库的替代品(查看比较)。如果你熟悉xUnit。Net,你已经准备好了xUnit++。
#include "xUnit++/xUnit++.h"
FACT("Foo and Blah should always return the same value")
{
Check.Equal("0", Foo()) <<"Calling Foo() with no parameters should always return \"0\".";
Assert.Equal(Foo(), Blah());
}
THEORY("Foo should return the same value it was given, converted to string", (int input, std::string expected),
std::make_tuple(0, "0"),
std::make_tuple(1, "1"),
std::make_tuple(2, "2"))
{
Assert.Equal(expected, Foo(input));
}
Main features:
主要特点:
Assert.Equal(-1, foo(i)) <<"Failed with i = " <
Log.Debug <<"Starting test"; Log.Warn <<"Here's a warning";
3
CppUTest - very nice, light weight framework with mock libraries. Worthwhile taking a closer look.
CppUTest -非常好,轻量级框架和模拟库。值得仔细看看。
3
CPUnit (http://cpunit.sourceforge.net) is a framework that is similar to Google Test, but which relies on less macos (asserts are functions), and where the macros are prefixed to avoid the usual macro pitfall. Tests look like:
CPUnit是一个类似于谷歌测试的框架,但它依赖的是更少的macos(断言是函数),而宏的前缀是为了避免通常的宏观陷阱。测试看起来像:
#include
namespace MyAssetTest {
using namespace cpunit;
CPUNIT_FUNC(MyAssetTest, test_stuff) {
int some_value = 42;
assert_equals("Wrong value!", 666, some_value);
}
// Fixtures go as follows:
CPUNIT_SET_UP(MyAssetTest) {
// Setting up suite here...
// And the same goes for tear-down.
}
}
They auto-register, so you need not more than this. Then it is just compile and run. I find using this framework very much like using JUnit, for those who have had to spend some time programming Java. Very nice!
他们自动注册,所以你只需要这个。然后它只是编译和运行。我发现使用这个框架非常类似于使用JUnit,对于那些不得不花一些时间编程Java的人来说。非常好!
2
There are some relevant C++ unit testing resources at http://www.progweap.com/resources.html
有一些相关的c++单元测试资源在http://www.prog武.com/resources.html。
2
API Sanity Checker — test framework for C/C++ libraries:
API完整性检查器- C/ c++库的测试框架:
An automatic generator of basic unit tests for a shared C/C++ library. It is able to generate reasonable (in most, but unfortunately not all, cases) input data for parameters and compose simple ("sanity" or "shallow"-quality) test cases for every function in the API through the analysis of declarations in header files.
一个用于共享C/ c++库的基本单元测试的自动生成器。它能够通过对头文件中声明的分析,生成合理的(在大多数情况下,但不幸的不是所有的情况)输入数据,并为API中的每个函数编写简单的(“健全”或“浅”质量)测试用例。
The quality of generated tests allows to check absence of critical errors in simple use cases. The tool is able to build and execute generated tests and detect crashes (segfaults), aborts, all kinds of emitted signals, non-zero program return code and program hanging.
生成的测试的质量允许在简单的用例中检查缺少关键错误。该工具能够构建和执行生成的测试和检测崩溃(seg故障)、中止、各种发出的信号、非零的程序返回代码和程序挂起。
Unique features in comparison with CppUnit, Boost and Google Test:
与CppUnit、Boost和谷歌测试相比较的独特功能: