2017-09-03 93 views
2

使用PhpUnit 6.3测试编写PHP 7.1中的helloWorld()函数。测试运行正常,如果我直接在命令行中执行它的PHP文件:PhpUnit配置错误:当使用<directory>时,没有运行测试

> 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节点最初。

+0

AFAIR PHPUnit只拾取尾部带'Test'命名的文件 - 如果包含文件扩展名,则使其成为'helloWorldTest.php'。 – xmike

回答

2
<phpunit> 
    <testsuites> 
     <testsuite name="Test suite"> 
      <directory suffix="_test.php">./hello-world</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 
相关问题