class Account{ var $balance; function Account($initialBalance=0){ $this->balance = $initialBalance; } function withdraw($amount){ $this->balance -= $amount; } function deposit($amount){ $this->balance += $amount; } function getBalance(){ return $this->balance; } function transferFrom(&$sourceAccount,$amount){ $sourceAccount->withdraw($amount); $this->deposit($amount); } ?>
function AccountTester($name){ $this->TestCase($name); // call parent constructor } function setUp(){ $this->_ac1 = new Account(100); // data for testWithdraw $this->_ac2 = new Account(20); // data for testDeposit $this->_ac3 = new Account(30); // data for testTransferFrom $this->_ac4 = new Account(50); } } ?>
加入专门的测试代码 现在,我们可以往向AccountTester类加入测试代码了。
<?php
// Make a withdrawal of 25 units from _ac1. // _ac1''s initial balance is 100