meekrosoft / fff

A testing micro framework for creating function test doubles
Other
749 stars 163 forks source link

Is it possible to mock static functions? #106

Open KasperZK opened 2 years ago

KasperZK commented 2 years ago

I presented the framework to my team and it raised some questions:

Can you mock static functions with this framework? For example would it be possible to mock and test a static function that is both defined and declared in the .c file that is to be tested? Do we even want to do this ever or should private functions only be accessed through public functions?

Thanks

nradulovic commented 2 years ago

Hi, you can only mock functions which are defined outside of tested implementation unit (.c).

In my projects I treat static functions as part of tested function so I don't need to mock them. When I get into the situation that I need to mock a static function, then that is a sign to me that I need to re-think about architecture of the code and ask some questions to myself.