51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2657|回复: 0
打印 上一主题 下一主题

[求助] 看过c++test6.7帮助文档的进,求助

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2012-10-30 09:34:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在学习使用的过程中用c++test测试如下代码时,分歧的T都没有走到,
  1. Account* Bank::getAccount(int num, string password)
  2. {
  3.     Account* userAccount = NULL;
  4.     if (myAccounts.size() > num)
  5.     {
  6.         userAccount = (Account*)myAccounts[num];
  7.     }
  8.     if ((userAccount != NULL) && (password.compare(userAccount->getPassword()) != 0))
  9.     {
  10.         // account wrong if account number does not match
  11.         userAccount = NULL;
  12.     }
  13.     // No account with this number/password exists!!!
  14.     return NULL;

  15. }
复制代码
帮助文档说加入自定义的测试用例来提高覆盖率,加入的代码如下:
  1. /* CPPTEST_TEST_CASE_BEGIN test_getAccount_positive_0 */
  2. void TestSuite_getAccount_0::test_getAccount_positive_0()
  3. {
  4. /* 前提条件初始化*/
  5. //我们的bank对象
  6. ::Bank _cpptest_TestObject ;
  7. //我们将为Bank对象cpptestTestObject添加两个账户
  8. const char * _password0 = "password0";
  9. const char * _password1 = "password1";
  10. ::Account * account0 = _cpptest_TestObject.addAccount();
  11. account0->setPassword( _password0 );
  12. ::Account * account1 = _cpptest_TestObject.addAccount();
  13. account1->setPassword( _password1 );
  14. /* getAccount(int, std:string) 函数接受账户的账号和密码*/
  15. int accountNumber = 0;
  16. /* 调用测试函数 */
  17. ::Account * _return = _cpptest_TestObject.getAccount( accountNumber, _password0);
  18. /* 后置条件检查: */
  19. /* 因为我设置了“harness.postConditions true”,C++test会给我一个可视化的后置条件*/
  20. CPPTEST_POST_CONDITION_PTR("Account * _return", ( _return ))
  21. CPPTEST_POST_CONDITION_INTEGER("int _cpptest_TestObject.myCurrentAccountNumber",
  22. ( _cpptest_TestObject.myCurrentAccountNumber ))
  23. CPPTEST_NOT_VALIDATED()
  24. }
复制代码
一开始添加了两个用户,能够看明白,之后在调用测试函数的那一步有些不太明白了,返回的值是什么?还有就是最下面的几个宏是干什么的?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-10 20:12 , Processed in 0.089687 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表