使用 PhpUnit 6.3
测试用 PHP 7.1
编写的 helloWorld()
函数。如果我直接从命令行执行它的 php 文件,测试运行正常:
> php C:\path\to\phpunit.phar C:\project\hello-world\hello-world_tests.php
OK <1 test, 1 assertion>
但是,如果我依赖我的配置文件,则不会运行测试:
> php C:\path\to\phpunit.phar --configuration C:\project\phpunit.xml
No tests executed!
这是我的文件夹结构:
project/
phpunit.xml
phpunit.phar
hello-world/
hello-world.php
hello-world_test.php
这是我的配置文件,phpunit.xml:
<phpunit>
<testsuites>
<testsuite name="Test suite">
<directory>./hello-world</directory>
</testsuite>
</testsuites>
</phpunit>
用 file
节点替换 directory
节点可以让事情正常工作:
<file>./hello-world/hello-world_test.php</file>
这很好,但我不想单独列出所有测试文件,这就是我最初拥有 directory
节点的原因。
最佳答案
<phpunit>
<testsuites>
<testsuite name="Test suite">
<directory suffix="_test.php">./hello-world</directory>
</testsuite>
</testsuites>
</phpunit>
关于PhpUnit配置错误: no tests run when <directory> is used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46025897/