测试多个文件夹

FMa*_*008 10 php phpunit unit-testing 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/
Run Code Online (Sandbox Code Playgroud)

考虑到我的主要测试文件夹(使用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>
Run Code Online (Sandbox Code Playgroud)

当我在Netbean中点击ALT + F6时,我只有来自/ test的测试.同样的事情:

/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here
Run Code Online (Sandbox Code Playgroud)

另外,我试过这个:

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

Could not use "modules" as loader.
Run Code Online (Sandbox Code Playgroud)

Gor*_*don 13

查看PHPUnit配置文件附录.您可以告诉PHPUnit要包含哪些文件夹:

<testsuites>
    <testsuite name="Submodules">
        <directory suffix="Test.php">../lib/*</directory>
    </testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)

当你运行它时,PHPUnit应递归迭代lib中的所有文件夹,并将所有以Test.php结尾的文件视为UnitTests.测试套件的名称无关紧要.为了简化XML文件的创作,请考虑使用我的phpunit-schema文件.

PHPUnit手册中有一些附加信息:使用Filesystem编写测试套件.Netbeans有一个输入对话框,您可以在其中指定phpUnit.xml和任何自定义TestSuite类的路径.

这是一个示例项目: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
Run Code Online (Sandbox Code Playgroud)