How to mock method with optional parameter in Google Mock?

前端 未结 3 759
醉酒成梦
醉酒成梦 2021-02-18 21:30

How to mock a method with optional parameter in Google Mock? For example:

class A
{ 
public:
    void set_enable( bool enabled = true );
};

cl         


        
3条回答
  •  清酒与你
    2021-02-18 21:42

    Some modifications to PiQuer's answer. You wouldn't need a wrapper if just add the name, "enabled" to the variable of type bool in your MOCK_METHOD1 like below:

    class A
    { 
        public:
        void set_enable( bool enabled = true );
    };
    
    class MockA : public A
    {
        MOCK_METHOD1( set_enable, void( bool enabled ) );
    };
    

提交回复
热议问题