"Important note: gMock requires expectations to be set before the mock functions are called, otherwise the behavior is undefined" In practice, this undefined behavior is impossible to prevent.