热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

c++单元测试框架的比较。-Comparisonofc++unittestframeworks

Iknowtherearealreadyafewquestionsregardingrecomendationsforc++unittestframeworks,but

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和新的谷歌测试框架。有人做过比较吗?

10 个解决方案

#1


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与其他框架进行比较的文章。

#2


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:

主要特点:

  • Portable
  • 可移植的
  • Fatal and non-fatal assertions
  • 致命的和非致命的断言
  • Easy assertions informative messages: ASSERT_EQ(5, Foo(i)) <<" where i = " <
  • 简单断言信息消息:ASSERT_EQ(5, Foo(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
  • SCOPED_TRACE为子程序循环
  • You can decide which tests to run
  • 您可以决定运行哪些测试。
  • XML test report generation
  • XML测试报告生成
  • Fixtures / Mock / Templates...
  • 设备/模拟/模板…

#3


91  

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:

我刚刚推出了自己的框架。它还在开发中,但我相信它已经超越了大多数其他框架。不同的人有不同的标准,但我尽量不做太多的权衡。看一看我的链接博客文章。我的五大特点是:

  • Header only
  • 头只
  • Auto registration of function and method based tests
  • 自动注册功能和基于方法的测试。
  • Decomposes standard C++ expressions into LHS and RHS (so you don't need a whole family of assert macros).
  • 将标准c++表达式分解为LHS和RHS(因此您不需要一个完整的assert宏家族)。
  • Support for nested sections within a function based fixture
  • 支持基于功能的fixture中的嵌套部分。
  • Name tests using natural language - function/ method names are generated
  • 使用自然语言-函数/方法名称进行名称测试。

It also has Objective-C bindings. The project is hosted on Github

它还有Objective-C绑定。该项目由Github托管。

#4


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:

它支持:

  • Automatic or manual tests registration
  • 自动或手动测试注册。
  • Many assertions
  • 很多人断言
  • Automatic comparison of collections
  • 自动收集的比较
  • Various output formats (including XML)
  • 各种输出格式(包括XML)
  • Fixtures / Templates...
  • 设备/模板……

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

PS:我写了一篇关于它的文章,可以帮助你入门:c++单元测试框架:Boost测试教程。

#5


19  

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

Wikipedia拥有一个完整的单元测试框架列表,其中有一些表可以识别支持的或不支持的特性。

#6


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:

主要特点:

  • 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 = " <
  • 容易维护日志:断言。等于(-1,foo(i)) <<
  • Test logging: 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
    • 名字子串matchin
    • Test Suites
    • 测试套件
  • 选择要运行的测试:属性匹配名称子字符串matchin测试套件。

#7


3  

CppUTest - very nice, light weight framework with mock libraries. Worthwhile taking a closer look.

CppUTest -非常好,轻量级框架和模拟库。值得仔细看看。

#8


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的人来说。非常好!

#9


2  

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

有一些相关的c++单元测试资源在http://www.prog武.com/resources.html。

#10


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和谷歌测试相比较的独特功能:

  • Automatic generation of test data and input arguments (even for complex data types)
  • 自动生成测试数据和输入参数(即使对于复杂的数据类型)
  • Modern and highly reusable specialized types instead of fixtures and templates
  • 现代和高度可重用的专门化类型,而不是固定装置和模板。

推荐阅读
author-avatar
cocoC陳靜雯具_606
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有