Google Mock: Is it ok to use global mock objects?
In all the documentation about gmock I always find the mock object to be instantiated inside a test, like that: TEST(Bim, Bam) { MyMockClass myMockObj; EXPECT_CALL(MyMockObj, foo(_)); ... } So, the object is created and destroyed per test. I believe it's also perfectly fine to create and destroy the object per test fixture . But I'm wondering if it's also ok to have a file-global instance of the mock object, like that: MyMockClass myMockObj; TEST(Bim, Bam) { EXPECT_CALL(MyMockObj, foo(_)) ... } I tried it and I have absolutely no problems so far, it all seems to work fine. But maybe I should