phpunit /排除文件仍返回警告

时间:2019-06-02 22:48:50

标签: php phpunit

使用版本8.1.6,并提供以下phpunit.xml:

<phpunit bootstrap="vendor/autoload.php">
  <testsuites>
    <testsuite name="SlimSkeleton">
      <directory>tests</directory>
      <exclude>./tests/Functional/BaseTestCase.php</exclude>
    </testsuite>
  </testsuites>
</phpunit>

以及以下目录结构:

  • ./tests/Functional/serviceA/...
  • ./tests/Functional/BaseTestCase.php

我一直得到以下输出:

...
1) Warning
No tests found in class "Tests\Functional\BaseTestCase".
...

我通过composer.json中的脚本命令运行suiter:

{
    ...
    "scripts": {
       "test": "phpunit"
      }
}

是预期的吗?有没有办法使这个警告静音?

1 个答案:

答案 0 :(得分:1)

phpunit默认情况下会找到*Test.php,因此即使在phpunit.xml中没有<exclude>,它也会通过运行composer test来忽略BaseTestCase.php。

  

使用测试而不是tests / EmailTest会指示PHPUnit命令行测试运行程序执行在tests目录中的* Test.php源代码文件中声明的所有测试。

https://phpunit.de/getting-started/phpunit-8.html

如果我指定如下所示的命令行参数,则会看到“未找到测试”警告。但这不是BaseTestCase.php from Slim-Skelton的预期用法。

$ composer test tests/Functional/BaseTestCase.php
> phpunit 'tests/Functional/BaseTestCase.php'
PHPUnit 8.1.6 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 21 ms, Memory: 4.00 MB

There was 1 warning:

1) Warning
No tests found in class "Tests\Functional\BaseTestCase".

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
相关问题