google mock – can I call EXPECT_CALL multiple times on same mock object?

Yes, you can call EXPECT_CALL on the same mock object multiple times. As long as you assure that all EXPECT_CALL were called before the mocked methods were actually used. Otherwise your test will rely on undefined behavior. From ForDummies: Important note: gMock requires expectations to be set before the mock functions are called, otherwise the … Read more

Dependency injection with unique_ptr to mock

Not something I would recommend in production environment actually, but aliasing constructor of shared_ptr represents maybe a dirty and working solution for your case. A minimal, working example (that doesn’t use gtest, sorry, I’m from mobile app and can’t test it directly): #include<memory> #include<iostream> #include<utility> struct IBar { virtual ~IBar() = default; virtual void DoSth() … Read more

Mocking free function

No it’s not possible, without changing the sources, or bringing your own version of foo() that is linked with the executable code. From GoogleMock’s FAQ it says My code calls a static/global function. Can I mock it? You can, but you need to make some changes. In general, if you find yourself needing to mock … Read more