??в????gmock?????
???????????? ???????[ 2015/10/29 14:34:27 ] ???????????????
???????gmock????
????gmock??google???????????????в???????gmock?????????????????????????????????漰??????????齻??????????????????mock???????????????????????????в????е???????
???????????????????в????е???????
????1?????????????????????????顣??????????????????????????????????μ??????????????????????????????gmock???????????????????????????????
????2???????????A??飬???A??????????B?????????????B??黹??????????????????gmock??B?????Щ?????????????????A???????????????????
????3???????????豸??????gtest????device???????????????????豸?????ò????????????????gmock??????sdk?????????????????豸????ò???????????
????????gmock??λ??
????gmock??google?????????google???????????????????????????????????????0.2????????“?з???????”??????????gmock???°汾??1.7.0??????????????????????“gmock-1.7.0.zip”??????????£?
????????????????????????gtest??????У??????????????gtest????????????????£?gmock?????gtest??????в?????????gtest?????????????????????????????
???????????????windows?μ?gmock?????????????????msvc????????С?msvc???????????2005??2010????У????????VS2005??VS2010??????????
??????VS2010?????????????????????????????gmock.lib??gmock_maim.lib??gmock_test.ext?????????????gmock.lib?????????????????????????????????????????????
????????gmock??????demo
????????????????????????????????????漰????????????????????????????п?ID??????????????????????????????????????????????д????????????????????????????????
??????????????mock??????????????????д??????????????????????????AccountManager.h ??
????// AccountManager.h
????// the interface of external services which should be mocked
????// ?????mock???????
????#pragma once
????#include <string>
????#include "Account.h"
????class AccountManager
????{
????public:
????//????????????????????
????virtual Account findAccountForUser(const std::string& userId) = 0;
????//????????????????
????virtual void updateAccount(const Account& account) = 0;
????};
????AccountManager???????mock?????????????findAccountForUser???????????????updateAccount???????????????????????mock???????????????????????????????????麯????????????????????????????????????????mock??????????У???????? ????????????
???????????gmock??mock?????AccountManager????????????
????// MockAccountManager?? mock AccountManager with googlemock
????class MockAccountManager : public AccountManager
????{
????public:
????MOCK_METHOD1(findAccountForUser?? Account(const std::string&));
????MOCK_METHOD1(updateAccount?? void(const Account&));
????};
??????MockAccountManager?????????DB??????AccountManager???????MOCK_METHOD1?gmock????塣?????л?????????????壬??MOCK_METHOD0??MOCK_METHOD2...
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11