Testing init() function in Google Test without invoking actual handler() function

28 Views Asked by At

I'm using Google Test for unit testing and I've hit a snag with a particular test case. Here's the situation:

I have a class called Test with a public function init(). Inside init(), there's a call to another function named handler() with specific parameters. The definition of handler() is in a separate C file, and its header file has already been included.The scenario is I am calling a C define function through a C++ class member function.

However, testing init() becomes tricky because handler() has a complex implementation. I want to write a test for init() without actually executing handler(). Instead I am looking for another way so that we can avoid calling the actual handler() function.

Here's a simplified version of the code structure:

#include "handler_header.h" // Included header file having the definition of handler() function

void Test::init() {
    ..........................
    handler(int, char*, char*);
    .........................
}

My goal is to test init() without triggering handler(). Does Google Test provide any solutions for mocking free/global function calls like handler()?

0

There are 0 best solutions below