本文翻译自:Comparison of C++ unit test frameworks [closed]
I know there are already a few questions regarding recommendations for C++ unit test frameworks, but all the answers did not help as they just recommend one of the frameworks but do not provide any information about a (feature) comparison. 我知道关于C ++单元测试框架的建议已经存在一些问题,但所有答案都没有帮助,因为他们只是推荐其中一个框架,但没有提供有关(特征)比较的任何信息。
I think the most interesting frameworks are CppUnit, Boost and the new Google testing framework. 我认为最有趣的框架是CppUnit,Boost和新的Google测试框架。 Has anybody done any comparison yet? 有人做过任何比较吗?
#1楼
参考:https://stackoom.com/question/11ca/C-单元测试框架的比较-关闭
#2楼
维基百科有一个完整的单元测试框架列表 ,其中包含可识别支持与否的功能的表。
#3楼
I've recently released xUnit++ , specifically as an alternative to Google Test and the Boost Test Library (view the comparisons ). 我最近发布了xUnit ++ ,特别是作为Google Test和Boost Test Library的替代品(查看比较 )。 If you're familiar with xUnit.Net, you're ready for xUnit++. 如果您熟悉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: 主要特点:
- Incredibly fast: tests run concurrently . 令人难以置信的快速:测试同时运行。
- Portable 手提
- Automatic test registration 自动测试注册
- Many assertion types (Boost has nothing on xUnit++) 许多断言类型(Boost在xUnit ++上没有任何内容)
- Compares collections natively. 本地比较集合 。
- Assertions come in three levels: 断言分为三个层次:
- fatal errors 致命错误
- non-fatal errors 非致命错误
- warnings 警告
- Easy assert logging:
Assert.Equal(-1, foo(i)) << "Failed with i = " << i;
简单的断言记录:Assert.Equal(-1, foo(i)) << "Failed with i = " << i;
- Test logging:
Log.Debug << "Starting test"; Log.Warn << "Here's a warning";
测试记录:Log.Debug << "Starting test"; Log.Warn << "Here's a warning";
Log.Debug << "Starting test"; Log.Warn << "Here's a warning";
- Fixtures 赛程
- Data-driven tests (Theories) 数据驱动测试(理论)
- Select which tests to run based on: 根据以下内容选择要运行的测试 :
- Attribute matching 属性匹配
- Name substring matchin 命名substring matchin
- Test Suites 测试套房
#4楼
http://www.progweap.com/resources.html上有一些相关的C ++单元测试资源
#5楼
See this question for some discussion. 有关讨论, 请参阅此问题 。
They recommend the articles: Exploring the C++ Unit Testing Framework Jungle , By Noel Llopis. 他们推荐文章: 探索C ++单元测试框架Jungle ,作者:Noel Llopis。 And the more recent: C++ Test Unit Frameworks 最近的: C ++测试单元框架
I have not found an article that compares googletest to the other frameworks yet. 我还没有找到一篇将googletest与其他框架进行比较的文章。
#6楼
A new player is Google Test (also known as Google C++ Testing Framework ) which is pretty nice though. 一个新的播放器是Google Test (也称为Google C ++测试框架 ),但它非常好用。
#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;
简单的断言信息性消息 :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 Google Test会自动检测您的测试,并且不需要您枚举它们才能运行它们
- Make it easy to extend your assertion vocabulary 可以轻松扩展断言词汇表
- Death tests (see advanced guide) 死亡测试 (参见高级指南)
-
SCOPED_TRACE
for subroutine loopsSCOPED_TRACE
用于子程序循环 - You can decide which tests to run 您可以决定运行哪些测试
- XML test report generation XML测试报告生成
- Fixtures / Mock / Templates ... 固定装置 / 模拟 / 模板 ......