0

I am using gtest/gmock framework to write unit tests. Following is my sample code.

In common.h,

void PreInit() {
  cout<<"Doing Pre-initialization."<<endl; 
}

In test.cpp,

 #include <common.h>
    class SampleComponent {
    public:
        void Init() {
           PreInit();
           // Do Initialization
        }
    } 

So far, I have been mocking classes. Any idea how to mock independent functions called by member functions of class?

Thanks in advance.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
user1228352
  • 569
  • 6
  • 21
  • You can't, you need to rethink your design to make it possible to inject a different function – Alan Birtles May 10 '20 at 06:49
  • I think there should be some way to mock C-style non-class function.. I could see few articles but wanted full example.. – user1228352 May 10 '20 at 12:10
  • Does this answer your question? [Mocking free function](https://stackoverflow.com/questions/28392277/mocking-free-function) – rveerd May 15 '20 at 15:42

0 Answers0