Saturday, June 23, 2018

unit testing - google mock - mock return value of a (free-standing) function called




I have a function that I'm testing, f1().



f1() calls g1() which can return a few different values.



How do I mock g1() so I can iterate through the different values it returns in order to test the paths inside f1()?



int f1()
{
int res = g1();

int ret = 0;
switch(res):
{
case 0:
// ret = something
case 1:
// ret = something else
default:
// ret = bad result
}

return ret;
}

Answer



Probably you can try cmocka tool to do the above mentioned use case.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...