eranpeer / FakeIt

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

Using global objects to assign output of get() method #253

Closed fgr-17 closed 1 year ago

fgr-17 commented 3 years ago

Hello!

I'm using FakeIt lib with Catch2. I'm having some issues when I try to verify global mocked objects methods execution.

First, a working example:

class SomeInterface {
  void fun(void) {}
}; 

TEST_CASE("mock test", "[test]") {

  Mock<SomeInterface> mock;
  Fake(Method(mock, fun));
  SomeInterface&i=mock.get();

  i.toggle();

  Verify((Method(mock, toggle)).AtLeastOnce();
}

But if the object assigned by mock.get() is global, the compilation builds OK, but the verify test fail.

How can I overcome this?

FranckRJ commented 3 years ago

Can you provide exactly the code that fails ? Looks like you may be copying the mock instead of using a reference to it but I'm not sure.

FranckRJ commented 1 year ago

I'll close it as there was no answer for one year.