如何解决:我编写测试后发现“未找到测试”?

时间:2019-07-25 15:01:58

标签: php phpunit

我正在学习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>

1 个答案:

答案 0 :(得分:1)

class testBalls应该是class BallTest