我只能在单元测试中使用 BOOST_CHECK 吗?
或者我可以在常规代码中使用它吗?
如果答案是“否”,那么是否有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它仅在单元测试中有意义,因为其目的是警告单元测试框架测试失败,然后继续。如果单元测试框架没有运行,那将无法工作。
在单元测试之外,您通常需要使用某种类型的断言。
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.
简短的回答是否定的。更长的答案:这些宏是 Boost.Test 的一部分。因此,如果您不使用 Boost.Test,您将不得不自己动手。
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.
基于 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)