繁体   English   中英

phpunit2“未执行测试”

[英]phpunit2 “Not tests executed”

嘿,我有一个小问题。

如果我使用phpunit,我可以运行我的测试,但是如果我尝试使用phpunit2,则它不起作用。

似乎找不到测试。

我只收到消息:“未执行测试”。

我正在使用xamppear 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM