【发布时间】:2015-06-15 23:10:05
【问题描述】:
通过加入测试驱动开发的潮流,试图成为一名优秀的后端开发人员 我刚刚通过 composer 安装了 PHPUnit。然后我运行命令 vendor/bin/phpunit 并且可以看到 PHPUnit 已正确安装。
下面是我的文件结构:
-fileserver
src
tests/
vendor
composer.json
composer.lock
index.php
phpunit.xml
在 phpunit.xml 文件中我有以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="File Server Test Suite">
<directory>./fileserver/tests/</directory>
</testsuite>
</testsuites>
</phpunit>
如果我运行 vendor/bin/phpunit 我可以看到我的配置文件已经加载但没有运行测试。
我基本上在测试文件夹中创建了一个简单的测试文件并扩展了 PHPUnit_Framework_TestCase。我所有的测试都使用 psr-4 命名空间 PhpUnitTest。
composer.json
//Other part excluded
"autoload": {
"psr-4": {
"FileServer\\": "src" ,
"PhpUnitTest\\": "tests"
}
示例测试类
namespace PhpUnitTest;
class StupidTest extends \PHPUnit_Framework_TestCase
{
public function testTrueIsTrue()
{
$foo = true;
$this->assertTrue($foo);
}
}
但是下面是我得到的输出:
PS C:\wamp\www\fileserver> vendor/bin/phpunit
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from C:\wamp\www\fileserver\phpunit.xml
Time: 3.53 seconds, Memory: 1.25Mb
←[30;43m←[2KNo tests executed!
←[0m←[2KPS C:\wamp\www\fileserver>
我错过了什么?为什么我的测试用例没有被执行?提前谢谢你。
【问题讨论】: