软件测试:在面向对象框架设计中重用内建自测试

发表于:2008-5-20 12:20

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:网络转载

分享:

qqq

图-3 BIT框架结构 

  4 BITs重用研究案例

        一个二分查找的 BIT对象的如标记B所示, 该BIT对象分为两部分:一般的方法(成员函数)和 BIT方法(函数)。该BIT对象中通过内建一个测试用例来说明BIT s方法。

        在常态模式下,标记B中普通的方法被调用:BITsBinarySearch::BinarySearch(int Key, int DataSet[10])。

        在测试模式下,内嵌的BIT成分通过调用 BITsBinarySearch::BIT1()被重用.

  Class BITsBinarySearch {

  ///////////////////////////////////////////////////////////////////////////// // 

   Interface

  ///////////////////////////////////////////////////////////////////////////// // 

   Member functions

  BITsBinarySearch(); // The constructor

  ~BITsBinarySearch(); // The destructor

  int BinarySearch (int Key; int DataSet[10]); // The conventional object

  void BIT1(); // The built-in-tests 1...3

  ///////////////////////////////////////////////////////////////////////////

  // Implementation

  ///////////////////////////////////////////////////////////////////////////

  // ================================

  // Part 1: The conventional function code

  // ================================

  int BinarySearch (int Key, int DataSet[10])

  {

  // The conventional object

  // Assume: DataSet is ordered

  // LastElement -FirstElement >=0

  // and FirstElement >=0

  // Input: Key to be found in the DataSet

  // Output: TestElemIndex

  Private:

  int bott, top, i;

  int found;

  found = false;

  Bott = 1;

  Top = ArraySize (DataSet); // The last element in DataSet

  while (bott <= top) && (not found)

  {

  i = floor ((bott + top)/2));

  if DataSet[i] == Key

  Found = true;

  else if DataSet[i] < Key

  Bott = i +1

  else Top = i +1;

  }

  if found == true

  return i; // The index of the element

  else return 0; // An indicator of not existence

  }

  // ==================================

  // Part 2: The BITs

  // ==================================

  // BIT case 1

  // ---------------------------------------------------------

  void BIT1()

  {

  // BIT case 1: Array size of 1, key in array

  private:

  int DataSet[1] = {16};

  int Key = 16;

  int StdElemIndex = 1;

  int TestElemIndex;

  char TestResult1[5];

  // Test implementation

  TestElemIndex = BinarySearch (Key, DataSet);

  // Test analysis

  cout << “StdElemIndex1 = ” << StdElemIndex << “\n”;

  cout << “TestElemIndex1 = ” << TestElemIndex << “\n”;

  if TestElemIndex == StdElemIndex

  TestResult1 = “OK”;

  else TestResult1 = “FALSE”;

  cout << “TestResult1: ” << TestResult1 << “\n”;

  }

  }

43/4<1234>
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号