如何为将回调作为其参数的函数编写单元测试

How to write unit test for a function that takes a call back as its argument?

本文关键字:函数 单元测试 参数 回调      更新时间:2023-10-16

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

unsigned __int32 
MyStream::DoThis(callBackFunction in_Function, 
                 unsigned __int32 in_Length)
{
    //some code
    //some code
    return readStream->DoThis(in_Function, dataLength);
}
  1. 创建一个存根回调函数,该函数在其主体内引发标志。
  2. 调用 UT 并将存根作为参数传递给函数。
  3. 执行完成后断言标志已升起。