c++ - 如何为将回调作为参数的函数编写单元测试?

标签 c++ unit-testing callback

如何为以回调函数为参数的函数编写单元测试?

unsigned __int32 
MyStream::DoThis(callBackFunction in_Function, 
                 unsigned __int32 in_Length)
{
    //some code
    //some code
    return readStream->DoThis(in_Function, dataLength);
}

最佳答案

  1. 创建一个 stub 回调函数,在其主体内引发标志。
  2. 调用您的 UT 并将 stub 作为参数传递给您的函数。
  3. 执行完成后断言标志已升起。

关于c++ - 如何为将回调作为参数的函数编写单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13445900/

相关文章:

python - 使用 py.test 在 Python 中测试正则表达式

java - Springboot 1.4/单元测试时出错(hibernate AttributeConverter 注册多次)

javascript - Node.js 在回调中获取 Exec 参数/命令

c++ - 在写入或读取 CFile 对象的过程中文件指针可以更改吗

c++ - 将整个 UTF-8 文件读入 std::string

c++ - 使用 extern inline 时 G++ 发出 "storage class specified"错误

java - Mockito 接口(interface)方法冲突

javascript - 低db : queries are synchronous or asynchronous?

javascript - 使用所有参数运行回调

c++ - 范围搜索的数据结构(重温)