C++单元测试框架 [英] C++ unit testing framework

查看:47
本文介绍了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++单元测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆