Google Mock: Mock private variable member that is instantiated in target class's constructor
- 阅读更多 关于 Google Mock: Mock private variable member that is instantiated in target class's constructor
问题 My question is the same as Mockito: Mock private field initialization but for Google Mock framework. In a nutshell: class Target { private: Person person = new Person(); public: void testMethod() { person.someMethod(); } }; How can I mock the person instance while making unit tests for Target class? 回答1: A non-answer here: simply don't do it this way. Your problem is the call to new here. Thing is: that makes testing hard, and it also creates a very tight coupling between the Target and the