eranpeer / FakeIt

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

Spying on callback function which is given as argument to the system under test #204

Closed JohnGreek closed 3 years ago

JohnGreek commented 4 years ago

Is it possible to spy on a callback which is given as argument to the system under test?

class SpyCallbackClass
{
public:
    virtual void cb() const {
    }
};

class SUT
{
public:
    SUT(const std::function<void(void)>& cb) :
        callback(cb)
    {

    }
    void DoStuff()
    {
        //Here for example, i want to test whether SUT does call cb
    }

private:
    const std::function<void(void)>& callback;
};
JohnGreek commented 3 years ago

I managed to resolve the issue. The problem was with my bind function, i was not using a pointer to the SpyCallbackClass but the object returned from Mock::get()