??в????gmock?????
???????????? ???????[ 2015/10/29 14:34:27 ] ???????????????
????MOCK_METHOD#1(#2?? #3(#4) )
????#2?????mock??????????#1??????mock????????м?????????#4???????????????????#3???????????????????????????????
// Account.h
// basic application data class
#pragma once
#include <string>
class Account
{
private:
std::string accountId; //???
long balance; //??? ?? ?????????
public:
Account();
Account(const std::string& accountId?? long initialBalance);
//????
void debit(long amount);
//????
void credit(long amount);
//??????
long getBalance() const;
//??????
std::string getAccountId() const;
};
???????????????????????????????????????????Account??debit?????????credit????????getBalance??????????getAccountId??????????????????
// A facility class acts as an external DB
class AccountHelper
{
private:
std::map<std::string?? Account> mAccount;
// an internal map to store all Accounts for test
public:
AccountHelper(std::map<std::string?? Account>& mAccount);
void updateAccount(const Account& account);
Account findAccountForUser(const std::string& userId);
};
AccountHelper::AccountHelper(std::map<std::string?? Account>& mAccount)
{
this->mAccount = mAccount;
}
void AccountHelper::updateAccount(const Account& account)
{
this->mAccount[account.getAccountId()] = account;
}
Account AccountHelper::findAccountForUser(const std::string& userId)
{
if (this->mAccount.find(userId) != this->mAccount.end())
return this->mAccount[userId];
else
return Account();
}
?????????????????????????????mock????????????????????????????????????
???????棬??????д?????????????????gmock?????????á?
????// Test case to test AccountService
????TEST(AccountServiceTest?? transferTest)
????{
????std::map<std::string?? Account> mAccount;
????mAccount["A"] = Account("A"?? 3000);
????mAccount["B"] = Account("B"?? 2000);
????AccountHelper helper(mAccount);
????MockAccountManager* pManager = new MockAccountManager();
????// specify the behavior of MockAccountManager
????// always invoke AccountHelper::findAccountForUser
????// when AccountManager::findAccountForUser is invoked
????EXPECT_CALL(*pManager?? findAccountForUser(testing::_)).WillRepeatedly(
????testing::Invoke(&helper?? &AccountHelper::findAccountForUser));
????// always invoke AccountHelper::updateAccount
????//when AccountManager::updateAccount is invoked
????EXPECT_CALL(*pManager?? updateAccount(testing::_)).WillRepeatedly(
????testing::Invoke(&helper?? &AccountHelper::updateAccount));
????AccountService as;
????// inject the MockAccountManager object into AccountService
????as.setAccountManager(pManager);
????// operate AccountService
????as.transfer("A"?? "B"?? 1005);
????// check the balance of Account("A") and Account("B") to
????//verify that AccountService has done the right job
????EXPECT_EQ(1995?? helper.findAccountForUser("A").getBalance());
????EXPECT_EQ(3005?? helper.findAccountForUser("B").getBalance());
????delete pManager;
????}
??????????????????MockAccountManager?????pManager????????????????AccountHelper???helper??EXPECT_CALL?????????????pManager?????滻???????helper?????????????????pManager??findAccountForUser?????滻??helper??findAccount????????pManager??updateAccount?????滻??helper??updateAccount??????
??????????gtest????????EXPECT_EQ???ж?????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??в?????в????????????Щ??????в??????в???????????????в??????????????????в??????в???????????????????????в????????????в????е????????????в???????????в???????????в???????????????Android??в????????????в????е????????????????е??в?????в??????в?????в????????????α?д??в??????в??????????????????в?????????в??????в?????????????????????в??????
???·???
??????????????????
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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????