eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.24k stars 170 forks source link

Mocking non-virtual methods #75

Closed ruipacheco closed 7 years ago

ruipacheco commented 7 years ago

GoogleMocks can mock non-virtual methods. Is it possible to use the same strategy with FakeIt?

https://github.com/google/googletest/blob/master/googlemock/docs/v1_7/CookBook.md#mocking-nonvirtual-methods

dascandy commented 7 years ago

You can use this same strategy with any other mocking library. It is not actually the library doing anything - you're doing all the heavy lifting by hand. Just define an equivalent interface, mock that and templatize your code on the type you actually want to use.

Or, with FakeIt and HippoMocks, add TEST_VIRTUAL to your functions and make them virtual for test purposes. Whichever approach suits you more. I tend not to like to templatize my code just for testing, on something that never changes.

ruipacheco commented 7 years ago

Thanks!