eranpeer / FakeIt

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

Mocking a void method? #8

Closed m-mcgowan closed 9 years ago

m-mcgowan commented 10 years ago

I have a interface like this:

struct Change {
    virtual void change(uint8_t r, uint8_t g, uint8_t b) =0;
};

In a test code like

function assertChanged(Mock<Change>& mock, uint8_t v1, uint8_t  v2, uint8_t v3) {
   Verify(Method(mock, change).Using(v1,v2,v3));
}

TEST_CASE(...) {
Mock<Change> mock;
Change* change = &mock.get();
When(Method(mock, change)).AlwaysReturn();
change->change(1, 2, 3);
assertChanged(mock, 1, 2, 3);
}

But I get

Unexpected method invocation: unknown()
  An unmocked method was invoked. All used virtual methods must be stubbed!

What am I doing wrong?

eranpeer commented 10 years ago

You are doing nothing wrong. Actually I just added your test to the file default_behaviore_tests.cpp and it passes. It is part of Fakeit tests on github now. I guess this is a another MinGW issue. I'll check it on MinGW soon and give you an accurate answer. Thank,

struct Change { virtual void change(uint8_t r, uint8_t g, uint8_t b) =0; };

void assertChanged(Mock& mock, uint8_t v1, uint8_t v2, uint8_t v3) { Verify(Method(mock, change).Using(v1,v2,v3)); }

void testPassMockByRef() { Mock mock; Change* change = &mock.get(); When(Method(mock, change)).AlwaysReturn(); change->change(1, 2, 3); assertChanged(mock, 1, 2, 3); }

On Thu, Sep 11, 2014 at 1:10 AM, Matthew McGowan notifications@github.com wrote:

I have a interface like this:

struct Change { virtual void change(uint8_t r, uint8_t g, uint8_t b) =0;};

In a test code like

function assertChanged(Mock& mock, uint8_t v1, uint8_t v2, uint8_t v3) { Verify(Method(mock, change).Using(v1,v2,v3));} TEST_CASE(...) {Mock mock;Change* change = &mock.get();When(Method(mock, change)).AlwaysReturn();change->change(1, 2, 3);assertChanged(mock, 1, 2, 3);}

But I get

Unexpected method invocation: unknown() An unmocked method was invoked. All used virtual methods must be stubbed!

What am I doing wrong?

— Reply to this email directly or view it on GitHub https://github.com/eranpeer/FakeIt/issues/8.

Eran 972-52-8387550

eranpeer commented 10 years ago

I have just ran the tests on MinGW 32 on my computer and your test passes. Can you please send me the exact details of the configuration you are using. BTW, I had to replace all std::to_string with my implementation fakeit::to_string since I got a compile error on MinGW32: error: ‘to_string’ is not a member of ‘std’. Don't you get this error too?

On Thu, Sep 11, 2014 at 5:55 AM, Eran Pe'er eranpe@gmail.com wrote:

You are doing nothing wrong. Actually I just added your test to the file default_behaviore_tests.cpp and it passes. It is part of Fakeit tests on github now. I guess this is a another MinGW issue. I'll check it on MinGW soon and give you an accurate answer. Thank,

struct Change { virtual void change(uint8_t r, uint8_t g, uint8_t b) =0; };

void assertChanged(Mock& mock, uint8_t v1, uint8_t v2, uint8_t v3) { Verify(Method(mock, change).Using(v1,v2,v3)); }

void testPassMockByRef() { Mock mock; Change* change = &mock.get(); When(Method(mock, change)).AlwaysReturn(); change->change(1, 2, 3); assertChanged(mock, 1, 2, 3); }

On Thu, Sep 11, 2014 at 1:10 AM, Matthew McGowan notifications@github.com wrote:

I have a interface like this:

struct Change { virtual void change(uint8_t r, uint8_t g, uint8_t b) =0; };

In a test code like

function assertChanged(Mock& mock, uint8_t v1, uint8_t v2, uint8_t v3) { Verify(Method(mock, change).Using(v1,v2,v3)); }

TEST_CASE(...) { Mock mock; Change* change = &mock.get(); When(Method(mock, change)).AlwaysReturn(); change->change(1, 2, 3); assertChanged(mock, 1, 2, 3); }

But I get

Unexpected method invocation: unknown() An unmocked method was invoked. All used virtual methods must be stubbed!

What am I doing wrong?

— Reply to this email directly or view it on GitHub.

Eran 972-52-8387550

Eran 972-52-8387550

eranpeer commented 10 years ago

Did you get a chance to pull the latest version and run the tests? I added your test to the set of fakeit unit tests and it passes. Please try to build & run the tests. If they pass then all is OK. If not, please send me the output. Thanks,

eranpeer commented 9 years ago

All tests pass (including the above example one). On all GCC, Clang, MSC, & MinGWx32.