CPPUNIT_ASSERT_EQUAL(-1, add.Add(2, -3));
}
...
好了好了,我不會再寫出愚蠢的代碼,我會實現Add了。
...
// Add two numbers
int Add(int first, int second)
{
return first + second;
}
...
OK,用例又通過了,太好了。
當然,這不是一個好例子,因為測試和開發的步伐太過于細小了,不過用來說事倒是還算不錯。好吧,還是讓大家都來做一個小練習。
實現一個CPrime類,它的聲明如下:
class CPrime
{
// Create a pool containing the primes less or equal the number "max"
// return true if create pool successfully, otherwise, return false
bool CreatePool(int max);
// Get a number from the pool
int GetPrime(int index);
文章來源于領測軟件測試網 http://www.kjueaiud.com/