通过PHAR在Windows上安装的PHPUnit 8显示未执行测试 [英] PHPUnit 8 installed on Windows through PHAR shows No tests are executed
问题描述
我通过PHAR安装了PHPUnit( https://phpunit.de/getting-started /phpunit-8.html ),并将phpunit添加到Windows 10中的系统变量中.
I installed PHPUnit through PHAR ( https://phpunit.de/getting-started/phpunit-8.html ) and added phpunit to my system variables in Windows 10.
现在,我正在尝试在CLI上使用phpunit运行一个测试用例,但是PHPUnit显示No tests executed!
.关键是我有5种测试方法.
Now I'm trying to run a test case with phpunit on the CLI, but PHPUnit shows No tests executed!
. The point is that I have 5 test methods.
我要测试的班级是这样:
The class I'm trying to test is this:
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));
}
}
当我在CLI中键入phpunit -v
时,我看到以下内容:
When I type phpunit -v
in CLI then I see this:
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)
有人可以为我指出解决此问题的正确思路吗?
Can someone point me to the right thinking direction to solving this problem?
为什么PHPUnit告诉我没有执行任何测试?
Why is PHPUnit telling me that No tests are executed?
我做错了什么?
推荐答案
对@assert
批注的支持已在很久以前删除.而且PHPUnit/Autoload.php
也在几年前被删除.
Support for the @assert
annotation was removed a long time ago. And PHPUnit/Autoload.php
was also removed years ago.
TL; DR,您需要阅读正式的入门指南(并且没有过时的信息提供了"IDE"的供应商,该IDE始终不支持最新版本的PHPUnit.
TL;DR You want to read the official Getting Started guide (and not outdated information provided the vendor of an "IDE" that does not support up-to-date versions of PHPUnit anyway).
这篇关于通过PHAR在Windows上安装的PHPUnit 8显示未执行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!