我只能在单元测试中使用 BOOST_CHECK 吗?

发布于 2024-08-07 15:49:43 字数 90 浏览 14 评论 0原文

或者我可以在常规代码中使用它吗?

如果答案是“否”,那么是否有 C++ 库可以为我提供所有宏,如 CHECK_EQUAL、CHECK_CLOSE 等?

Or Can I use it in regular code?

If the answer is "no", then is there C++ library that will provide me with all the macros like CHECK_EQUAL, CHECK_CLOSE, etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朦胧时间 2024-08-14 15:49:43

它仅在单元测试中有意义,因为其目的是警告单元测试框架测试失败,然后继续。如果单元测试框架没有运行,那将无法工作。

在单元测试之外,您通常需要使用某种类型的断言。

It is only meaningful in unit tests, since its purpose is to alert the unit testing framework that a test failed, and then continue. If the unit testing framework isn't running, that won't work.

Outside unit tests, you'll usually want to use some flavor of assert instead.

失退 2024-08-14 15:49:43

如果答案是“否”,那么是否有 C++ 库可以为我提供所有宏
例如 CHECK_EQUALCHECK_CLOSE 等?

简短的回答是否定的。更长的答案:这些宏是 Boost.Test 的一部分。因此,如果您不使用 Boost.Test,您将不得不自己动手。

If the answer is "no", then is there C++ library that will provide me with all the macros
like CHECK_EQUAL, CHECK_CLOSE, etc.?

The short answer is no. The longer answer: These macros are part of Boost.Test. So, if you are not using Boost.Test you will have to roll your own.

猫烠⑼条掵仅有一顆心 2024-08-14 15:49:43

基于 boost/assert 或 cassert 编写此功能相当容易。
但请注意,断言可能需要一些定义(例如 DEBUG)

It's fairly easy to write this functionality based on boost/assert or cassert.
Note, however, that assertions may require some definitions (such as DEBUG)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文