Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I call an actual method of a "mocked" object? #1

Closed
jpeterman1 opened this issue Jun 3, 2014 · 2 comments
Closed

Can I call an actual method of a "mocked" object? #1

jpeterman1 opened this issue Jun 3, 2014 · 2 comments

Comments

@jpeterman1
Copy link

Sometimes it can be convenient to use the methods of the real underlying class that is being mocked rather that having to stub out everything. Is that possible with FakeIt?

Thanks,
JP

@jpeterman1 jpeterman1 changed the title Can I call the actualy method of a "mocked" object Can I call an actual method of a "mocked" object? Jun 3, 2014
@eranpeer
Copy link
Owner

eranpeer commented Jun 3, 2014

Thank you for trying FakeIt.
Currently, FakeIt doesn't support spying an object or partially mocking a
class.
I'm looking for a technical solution that will enable spying in both GCC
and MSC++.
Hopefully, I'll be able to support spying soon.

Regards,
Eran.

On Tue, Jun 3, 2014 at 6:39 AM, jpeterman1 notifications@github.com wrote:

Sometimes it can be convenient to use the methods of the real underlying
class that is being mocked rather that having to stub out everything. Is
that possible with FakeIt?

Thanks,
JP


Reply to this email directly or view it on GitHub
#1.

Eran
972-52-8387550

@eranpeer
Copy link
Owner

eranpeer commented Jun 8, 2014

I added spying functionality. It is now possible to spy an object by simply writing:

SomeClass obj;
Mock<SomeClass> spy(obj);

Here is the complete example:

struct SomeClass {
    virtual int func1(int arg) {
        return arg;
    }
    virtual int func2(int arg) {
        return arg;
    }
};

void useOriginalClassMethodIfNotStubbed() {
    SomeClass obj;
    Mock<SomeClass> spy(obj);
    When(spy[&SomeClass::func1]).Return(0); // Override func1 to return 0.
    SomeClass& i = spy.get();
    ASSERT_EQUAL(0, i.func1(1)); // func1 should return 0 
    ASSERT_EQUAL(1, i.func2(1)); // func2 should stay unmocked
}

You can check for more examples at tests/spying_tests.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants