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 )
文章来源于领测软件测试网 https://www.ltesting.net/