[英]phpunit2 “Not tests executed”
嘿,我有一個小問題。
如果我使用phpunit,我可以運行我的測試,但是如果我嘗試使用phpunit2,則它不起作用。
似乎找不到測試。
我只收到消息:“未執行測試”。
我正在使用xamp與pear 1.9.4,php 5.5.9 zend 2.5.0。
這些文件位於phpunit.bat所在的xampp / php文件夾中。
BankAccount.php
<?php
class BankAccount {
private $fBalance = 0;
public function getBalance() {
return $this->fBalance;
}
public function setBalance($balance) {
if ($balance >= 0) {
$this->fBalance = $balance;
}
}
public function depositMoney($amount) {
if (is_numeric($amount) &&
$amount >= 0) {
$this->fBalance += $amount;
}
}
public function withdrawMoney($amount) {
if (is_numeric($amount) &&
$amount >= 0 &&
$this->fBalance >= $amount) {
$this->fBalance -= $amount;
}
}
}
?>
BankAccountTest.php
<?php
require_once 'BankAccount.php'; // zu testende Klasse
require_once 'PHPUnit2/Framework/TestCase.php'; // Einbinden der Pear-Klasse
class BankAccountTest extends PHPUnit2_Framework_TestCase {
public function testBalanceIsInitiallyZero() {
$ba = new BankAccount;
$this->assertEquals(0, $ba->getBalance());
}
public function testBalanceCannotBecomeNegative() {
$ba = new BankAccount;
$ba->withdrawMoney(1);
$this->assertEquals(0, $ba->getBalance());
$ba = new BankAccount;
$ba->setBalance(-1);
$this->assertEquals(0, $ba->getBalance());
}
}
?>
任何幫助,高度贊賞!
這是Adam Trachtenberg和David Sklar的PHP Cookbook的引言,第619頁:
PHPUnit2僅適用於PHP5,而PHPUnit將在PHP5或PHP4下運行。
結論:您可以使用PHPUnit2_Framework_TestCase
測試您的代碼。 但是為了簡單起見,並且由於您現在遇到的問題,只需使用PHPUnit_Framework_TestCase
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.