gmock的神奇作用
// Test case to test AccountService
TEST(AccountServiceTest, transferTest)
{
std::map
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;
}
请联系网站,了解详细的优惠课程信息~
优质、便捷、省心
网上报名
新闻资讯
更多>>-
想在北京学软件测试,哪个机构更靠谱儿?
2016-11-15
-
常见软件测试面试题
2016-12-23
-
黑盒测试人员有发展前途吗?
2016-12-23
-
女生学软件测试好不好?
2016-12-23
-
软件测试的创新之道
2016-12-23