PhpUnit配置错误: no tests run when <directory> is used

标签 php phpunit

使用 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/

相关文章:

PHPUnit 代码覆盖率和异常

php - 值在 TextView 中未传递到 Mysql 数据库

javascript - Yii2 向下拉列表表单字段添加类或函数

javascript - 如果 id 与 php 中的 session id 不相关,如何重定向页面

php - Laravel - CircleCI - 在 phpunit 上失败

intellij-idea - 在 IntelliJ/PhpStorm 中更改测试根路径/模式

php - 如何检查php中的某些扩展

php - 在 php 中使用 fpdf 创建带有包装数据的 pdf 表格

command-line - PHPUnit 只能从命令行运行。为什么?

php - 在单元测试时使用 Laravel 辅助函数