Giter Site home page Giter Site logo

Comments (2)

eranpeer avatar eranpeer commented on June 15, 2024

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 [email protected] 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

from fakeit.

eranpeer avatar eranpeer commented on June 15, 2024

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

from fakeit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.