您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > cppUnit
CPPUnit實(shí)例Simple class
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/15 14:10:45 ] 推薦標(biāo)簽:

        1. CppUnit是xUnit系列中的c++實(shí)現(xiàn)版本,它是從JUnit移植過來的,第一個(gè)移植版本由Michael Feathers完成,安裝cppunit,你可以在此下載cppunit的新版本,新版本是CppUnit release 1.12.0,安裝方法,現(xiàn)解壓,然后到文件夾下找到INSTALL-WIN32.txt(windows平臺)

        2.打開examples下的examples.dsw,編譯鏈接即可完成。

        3.分析所要測試的類class

class Money
{
public:
  Money( double amount, std::string currency )
    : m_amount( amount )
    , m_currency( currency )
  {
  }

  double getAmount() const
  {
    return m_amount;
  }

  std::string getCurrency() const
  {
    return m_currency;
  }

  bool operator ==( const Money &other ) const
  {
    return m_amount == other.m_amount  &&
           m_currency == other.m_currency;
  }

  bool operator !=( const Money &other ) const
  {
    return !(*this == other);
  }

  Money &operator +=( const Money &other )
  {
    if ( m_currency != other.m_currency )
      throw IncompatibleMoneyError();

    m_amount += other.m_amount;
    return *this;
  }

private:
  double m_amount;
  std::string m_currency;
};

        4. 所要測試的有哪些接口呢?

        我們分析一下這個(gè)類的公開的屬性和方法。這些都是我們要測試的接口。

構(gòu)造函數(shù)
Money( double amount, std::string currency )
接口函數(shù)有
double getAmount() const
std::string getCurrency() const
bool operator ==( const Money &other ) const
bool operator !=( const Money &other ) const
Money &operator +=( const Money &other )

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd