Saturday 23 June 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...