简体   繁体   中英

i want to write gmock google test cases for the below scenario

i have set of functions within the Singleton class. i want to mock a function in the singleton class. Lets take the below piece of code.The function setname() will return the string from the classyyy's setname() funciton. so here i want to test the return value.so please tell me how to write the test case for this situation.

class mockBtMxxx : public BTMxxx
{
public:
    MOCK_METHOD2(setname, string(const int& id, const string& name));
};

// Test case for Setting Local Device Friendly Name.
TEST(TestBTC, GMockSetNameTest)
{
    mockBtMxxx mock_Btm;
    int id = 12345;
    string str = "Hello";
    EXPECT_CALL(mock_Btm, setname(_,_)).WillOnce(Return("Hello"));
}

I am getting the below errors : error: 'BTMxxx::BTMxxx()' is private gmock-actions.h:491:66: error: no matching function for call to 'ImplicitCast_(const char*&)'

For your first error, you need to make the constructor of your base class callable from the derived class. While you have not shown the declaration of class BTM , it is easy to guess that you have the constructor declared as private currently. I suggest making BTMxxx::BTMxxx() protected so it can be called by the mock class's default constructor.

As to your second error, the return type of setname is probably being deduced as const char* . You need to provide a std::string object in order for it to match the exact return type.

For a more complete picture of your problem, please provide the actual code for the BTMxxx class and specify what platform and compiler you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM