【发布时间】:2014-08-03 15:32:56
【问题描述】:
是否可以模拟检索指针(或引用)作为参数并更改指向对象的方法?
我使用海龟库 - http://turtle.sourceforge.net/ -> 用于 Boost 的 C++ 模拟对象库。 (我知道它不是流行的库,但在其他库中可能类似)。
例如:我需要将方法模拟为:
int f(int* x)
{
*x = new_value;
return 0;
}
下一个 SUT 在代码中使用 x 值:(
我可以设置我的模拟返回什么。但是修改参数呢?
怎么做?
【问题讨论】:
-
用
*x = new_value;替换// *x is modified (object pointed by x is modified) -
这是 SUT(被测系统)中的方法。我需要在我的测试中模拟这种方法的行为(在预期中)。
标签: c++ unit-testing boost mocking turtle-mock