Hey i got a little problem.
If i use phpunit i can run my test but if i try to use phpunit2 it doesnt work.
It seems like it cant find the tests.
I only get the message: "No Tests executed".
I'm using xamp with pear 1.9.4, php 5.5.9 zend 2.5.0.
The files are in the xampp/php folder where the phpunit.bat is.
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());
}
}
?>
Any help highly appreciated!..
This is a quote from PHP Cookbook by Adam Trachtenberg and David Sklar, Page 619:
PHPUnit2 is for PHP5 only, whereas PHPUnit will work under PHP5 or PHP4.
In conclusion: You can use PHPUnit2_Framework_TestCase
to test your code. But for simplicity, and because of the problems you have now, just use PHPUnit_Framework_TestCase
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.