在加速测试框架的测试断言 [英] Testing for assert in the Boost Test framework

查看:127
本文介绍了在加速测试框架的测试断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Boost测试框架进行单元测试我的C ++ code,不知道是否有可能以测试功能将断言?是的,听起来有点怪,但我承担!我的很多功能在入境检查输入的参数,如果他们是无效的主张,而且这将是测试这个非常有用。例如:

I use the Boost Test framework to unit test my C++ code and wondered if it is possible to test if a function will assert? Yes, sounds a bit strange but bear with me! Many of my functions check the input parameters upon entry, asserting if they are invalid, and it would be useful to test for this. For example:

void MyFunction(int param)
{
    assert(param > 0); // param cannot be less than 1
    ...
}

我希望能够做这样的事:

I would like to be able to do something like this:

BOOST_CHECK_ASSERT(MyFunction(0), true);
BOOST_CHECK_ASSERT(MyFunction(-1), true);
BOOST_CHECK_ASSERT(MyFunction(1), false);
...

您可以检查异常使用Boost测试,所以我想知道是否有一些神奇的断言被抛出过...

You can check for exceptions being thrown using Boost Test so I wondered if there was some assert magic too...

推荐答案

我不这么认为。你总是可以编写自己的断言它抛出一个异常,然后使用BOOST_CHECK_NOTHROW()为例外。

I don't think so. You could always write your own assert which throws an exception and then use BOOST_CHECK_NOTHROW() for that exception.

这篇关于在加速测试框架的测试断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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