C++ unit testing framework(C++单元测试框架)
问题描述
我将 Boost Test 框架用于我的 C++ 代码,但它有两个问题可能是所有 C++ 测试框架都共有的:
I use the Boost Test framework for my C++ code but there are two problems with it that are probably common to all C++ test frameworks:
- 无法创建自动测试存根(例如,通过从选定的类中提取公共函数).
- 您不能运行单个测试 - 您必须运行整个套件"测试(除非我猜您创建了许多不同的测试项目).
有谁知道更好的测试框架,还是我永远嫉妒 Java/.NET 开发人员可用的测试工具?
Does anyone know of a better testing framework or am I forever to be jealous of the test tools available to Java/.NET developers?
推荐答案
我刚刚回复了一个非常相似的问题.我最终使用了 Noel Llopis 的 UnitTest++.我比 boost::test 更喜欢它,因为它不坚持使用宏来实现测试工具的主程序 - 它可以插入您创建的任何可执行文件.它确实受到了 boost::test 的相同负担,因为它需要链接一个库.我使用过 CxxTest,它确实比 C++ 领域中的其他任何东西都更接近于自动生成测试(尽管它需要 Perl成为构建系统的一部分来执行此操作).C++ 只是不提供 .NET 语言和 Java 提供的反射钩子.Visual Studio Team System - Developer's Edition 中的 MsTest 工具将自动生成非托管 C++ 的测试存根,但必须从 DLL 导出方法才能执行此操作,因此它不适用于静态库..NET 世界中的其他测试框架也可能具有这种能力,但我对其中任何一个都不熟悉.所以现在我们将 UnitTest++ 用于非托管 C++,而我目前正在为托管库决定在 MsTest 和 NUnit 之间.
I just responded to a very similar question. I ended up using Noel Llopis' UnitTest++. I liked it more than boost::test because it didn't insist on implementing the main program of the test harness with a macro - it can plug into whatever executable you create. It does suffer from the same encumbrance of boost::test in that it requires a library to be linked in. I've used CxxTest, and it does come closer than anything else in C++-land to automatically generating tests (though it requires Perl to be part of your build system to do this). C++ just does not provide the reflection hooks that the .NET languages and Java do. The MsTest tools in Visual Studio Team System - Developer's Edition will auto-generate test stubs of unmanaged C++, but the methods have to be exported from a DLL to do this, so it does not work with static libraries. Other test frameworks in the .NET world may have this ability too, but I'm not familiar with any of those. So right now we use UnitTest++ for unmanaged C++ and I'm currently deciding between MsTest and NUnit for the managed libraries.
这篇关于C++单元测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++单元测试框架


基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01