We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何在同一个用例中mock同一个函数多次,并且期望的行为每次都不同? 例如下面的示例:
class a { public: int aFunc(int i) { // do something, return different value // or read differen value from file... } }; class call { public: int call_aFunc(int x) { int ret = 0; if (x==y) { ret = x * aobj.aFunc(x); // expect return 2 } else if (x%y==0) { ret = x % aobj.aFunc(x); // expect return 10 rer += y*aobj.aFunc(y); // expect return 6 } else if (x/y) { rer += y/aobj.aFunc(y); // expect return 8 } else { rer += aobj.aFunc(x); // expect return 0 } return rer += aobj.aFunc(ret); // expect return 666 } a aobj; int y; };
mockcpp中有类似的语法: .stubs().will(returnValue(10)).then(returnValue(6)).then(returnVaule(666));
emock也支持类似的语法,但是实测then没效果,每次返回的都是will中设定的10.
系统:Linux x86_64,编译器:g++
The text was updated successfully, but these errors were encountered:
连续调用目前没有限制,但是就和实际效果一致,单条约定中设置多个返回后续的不会生效,可以考虑以下方案: 方案一,用returnObjectList
returnObjectList
will(returnObjectList(10, 6, 666))
方案二,用invoke
invoke
will(invoke(mock_func))
在mock_func里控制返回的值
mock_func
方案三,写成多条约定
EMOCK(xxx).expects(once()).will(returnValue(10)); EMOCK(xxx).expects(once()).will(returnValue(6)); EMOCK(xxx).expects(once()).will(returnVaule(666));
Sorry, something went wrong.
感谢大佬回复。我试试看
No branches or pull requests
如何在同一个用例中mock同一个函数多次,并且期望的行为每次都不同?
例如下面的示例:
mockcpp中有类似的语法:
.stubs().will(returnValue(10)).then(returnValue(6)).then(returnVaule(666));
emock也支持类似的语法,但是实测then没效果,每次返回的都是will中设定的10.
系统:Linux x86_64,编译器:g++
The text was updated successfully, but these errors were encountered: