php - 测试多个文件夹

标签 php unit-testing phpunit project-organization test-suite

我在项目中使用 PHPUnit 3.5.12、netbean 6.9 和 git 子模块。

所以我的文件夹架构看起来像这样:

lib/
lib/submodule1
lib/submodule1/src
lib/submodule1/tests
lib/submodule2
lib/submodule2/src
lib/submodule2/tests
src/
tests/

考虑到我的主要测试文件夹(带有 phpunit_netbean.xml 和 bootstrap.php)在/tests/文件夹中;我怎样才能在/lib/*/tests/中运行测试?

我看过测试套件,但我无法让它工作。到目前为止,我已经在我的 tests/phpunit_netbean.xml 文件中尝试了以下配置:

<?xml version="1.0"?>
<phpunit
    bootstrap="./bootstrap.php"
    strict="true"
    stopOnError="false"
    stopOnFailure="false"
    stopOnIncomplete="false"
    stopOnSkipped="false"
    colors="false"
    verbose="true"
    >

    <testsuites>
        <testsuite name="modules">
            <directory>../lib/*</directory>
        </testsuite>
    </testsuites>

</phpunit>

当我在 Netbean 中按下 ALT+F6 时,我只运行了来自/tests 的测试。同样的事情:

/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here

另外,我试过这个:

/tests$ phpunit -c phpunit_netbean.xml --testdox --loader modules ./
PHPUnit 3.5.12 by Sebastian Bergmann.

Could not use "modules" as loader.

最佳答案

看看 Appendix for your PHPUnit config file .您可以告诉 PHPUnit 要包含哪些文件夹:

<testsuites>
    <testsuite name="Submodules">
        <directory suffix="Test.php">../lib/*</directory>
    </testsuite>
</testsuites>

当您运行它时,PHPUnit 应该递归地遍历 lib 中的所有文件夹,并将所有以 Test.php 结尾的文件视为单元测试。测试套件的名称无关紧要。为了简化 XML 文件的创作,consider using my phpunit-schema file .

PHPUnit Manual Chapter: Composing a Test Suite Using the Filesystem 中有一些额外的信息.Netbeans 有一个 input dialog in which you can specify the path to the phpUnit.xml and any custom TestSuite Class.

这是一个示例项目:https://github.com/gooh/sample

C:\Users\Gordon\Desktop\demo\tests>phpunit --testdox
PHPUnit 3.5.13 by Sebastian Bergmann.

A
 [x] One

B
 [x] One

My
 [x] One

关于php - 测试多个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5500558/

相关文章:

php - 选择具有相同 ID 的 * 并将每个 ID 放入不同的变量

selenium - 对刚刚执行了 type() 的元素进行 verifyText() 有意义吗?

phpunit - 如果调试客户端未在监听,则 xdebug.start_start_with_request=yes WITHOUT 错误

php - 如何将此字符串拆分为数组?

php - 将 LaTeX 渲染为图像

PHP MySQL : Go through each row, 并计算有多少列满足条件

perl - 我如何在 Perl 中进行单元测试?

java - 是否可以为单元测试目的强制设置一个内部变量?

perl - 有没有一种简单的方法可以为 perl 测试设置一个本地的、独立的 Web 服务器?

mysql - 如何在开发和生产中使用不同的数据库