我正在学习phpunit,我写了一个简单的测试,但是当我尝试使用控制台启动它时,它找不到。我用以下命令启动phpunit:“ ./ vendor / bin / phpunit”
这是测试。它位于./tests /
?php
require 'app/ball.php';
class testBalls extends PHPUnit\Framework\TestCase
{
public $ballInstance;
public function setUp()
{
$this->ballInstance = new Ball();
}
public function testStealing(){
$this->ballInstance->setBalls(100);
$this->ballInstance->stealBall();
$this->assertEquals(99,$this->ballInstance->getBalls());
}
}
这是经过测试的php脚本。它位于./app /
<?php
class Ball{
private $ballCount;
public function getBalls(){
return $this->ballCount;
}
public function setBalls($number){
$this->ballCount = $number;
}
public function stealBall(){
$this->ballCount = $this->getBalls()-1;
}
}
这是phpunit配置
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Test suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
答案 0 :(得分:1)
class testBalls
应该是class BallTest
。