断言和单元测试不兼容吗? [英] Is assert and unit-testing incompatible?

查看:72
本文介绍了断言和单元测试不兼容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对测试某些包含来自 assert的断言宏的函数的事实感到担忧. h .

I have some concerns related to the fact of testing some functions containing the assert macro from assert.h.

如果断言失败,则测试也将失败. 这给我留下了一些永远无法使用的测试用例.

If the assert fails the test fails also. This leaves me with some test cases that will never work.

例如,声明函数而不是指示失败(返回false或类似的东西)的断言.

For example a function instead of indicating failure (return false or something similar) asserts.

是否有解决方案(包含assert的单元测试功能)?

Is there a solution for this (unit-testing functions containing assert)?

推荐答案

不,单元测试是您在开发过程中要做的.断言是一个运行时构造.

No, unit testing is what you do during development. Asserts are a run-time construct.

根据我的经验,在大多数情况下,断言在生产中都处于关闭状态.但是您应该始终在进行测试.

In my experience, most of the time asserts are turned off in production. But you should always be testing.

CppUnit是一个很好的测试框架.它是C ++的nUnit系列的一部分.

CppUnit is a fine test framework. It's part of the nUnit family for C++.

这篇关于断言和单元测试不兼容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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