CPPUnit实例Simple class

发表于:2007-8-08 16:05

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

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

        1. CppUnit是xUnit系列中的c++实现版本,它是从JUnit移植过来的,第一个移植版本由Michael Feathers完成,安装cppunit,你可以在此下载cppunit的最新版本,最新版本是CppUnit release 1.12.0,安装方法,现解压,然后到文件夹下找到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. 所要测试的有哪些接口呢?

        我们分析一下这个类的公开的属性和方法。这些都是我们要测试的接口。

构造函数
Money( double amount, std::string currency )
接口函数有
double getAmount() const
std::string getCurrency() const
bool operator ==( const Money &other ) const
bool operator !=( const Money &other ) const
Money &operator +=( const Money &other )

31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号