Я установил PHPUnit через PHAR (https://phpunit.de/getting-started/phpunit-8.html) и добавил phpunit к своим системным переменным в Windows 10.
Сейчас я пытаюсь запустить тестовый пример с phpunit на CLI, но PHPUnit показывает No tests executed!
. Дело в том, что у меня есть 5 методов испытаний.
Класс, который я пытаюсь проверить, таков:
class Calculator
{
/**
* @assert (0, 0) == 0
* @assert (0, 1) == 1
* @assert (1, 0) == 1
* @assert (1, 1) == 2
* @assert (1, 2) == 4
*/
public function add($a, $b)
{
return $a + $b;
}
}
Найдено по адресу: https://netbeans.org/kb/docs/php/phpunit.html
И мой тестовый пример такой:
require_once 'PHPUnit/Autoload.php';
use PHPUnit\Framework\TestSuite;
class CalculatorTest extends TestSuite {
//class CalculatorTest extends PHPUnit_Framework_TestCase {
/**
* @var Calculator
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp(): void {
$this->object = new Calculator;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown(): void {
}
/**
* Generated from @assert (0, 0) == 0.
*
* @covers Calculator::add
*/
public function testAdd(): void {
$this->assertEquals(0, $this->object->add(0, 0));
}
/**
* Generated from @assert (0, 1) == 1.
*
* @covers Calculator::add
*/
public function testAdd2(): void {
$this->assertEquals(1, $this->object->add(0, 1));
}
/**
* Generated from @assert (1, 0) == 1.
*
* @covers Calculator::add
*/
public function testAdd3(): void {
$this->assertEquals(1, $this->object->add(1, 0));
}
/**
* Generated from @assert (1, 1) == 2.
*
* @covers Calculator::add
*/
public function testAdd4(): void {
$this->assertEquals(2, $this->object->add(1, 1));
}
/**
* Generated from @assert (1, 2) == 4.
*
* @covers Calculator::add
*/
public function testAdd5(): void {
$this->assertEquals(4, $this->object->add(1, 2));
}
}
Когда я набираю phpunit -v
в CLI, я вижу это:
C:\wamp64\www\test>phpunit -v
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.
Usage:
phpunit [options] UnitTest [UnitTest.php]
phpunit [options] <directory>
Code Coverage Options:
--coverage-clover <file> Generate code coverage report in Clover XML format
--coverage-crap4j <file> Generate code coverage report in Crap4J XML format
--coverage-html <dir> Generate code coverage report in HTML format
--coverage-php <file> Export PHP_CodeCoverage object to file
--coverage-text=<file> Generate code coverage report in text format [default: standard output]
--coverage-xml <dir> Generate code coverage report in PHPUnit XML format
--whitelist <dir> Whitelist <dir> for code coverage analysis
--disable-coverage-ignore Disable annotations for ignoring code coverage
--no-coverage Ignore code coverage configuration
--dump-xdebug-filter <file> Generate script to set Xdebug code coverage filter
Моя система:
Windows 10
WAMP
php 7.2.14
PHPUnit 8.0.6
Netbeans version 8.2 (Netbeans PHPUnit plugin installed through Tools > Plugins. Version: 0.26.2)
Installation method: PHP Archive (PHAR)
Может ли кто-нибудь указать мне правильное направление мышления для решения этой проблемы?
Почему PHPUnit сообщает мне, что тесты не выполняются?
Что я сделал не так?