2

在我的应用程序中,我在源代码旁边有 phpunit 测试。所以在接下来的所有地图中,假设 DoSometing.class.php 我有一个 DoSomethingTest.class.php。

我想配置 phpunit.xml 来测试所有这些 *Test.class.php 文件。

我该如何在 phpunit.xml 中做到这一点?

我现在有这样的事情:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit 
    backupGlobals="false"
    backupStaticAttributes="true"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    processIsolation="true"
    stopOnFailure="true"
    syntaxCheck="false">
    <testsuites>
        <testsuite name="My Test Suite">
            <directory>./*Test.class.php</directory>
        </testsuite>
    </testsuites>
    <groups />
    <filter />
    <logging />
    <listeners />
</phpunit>
4

1 回答 1

2

我们使用类似的结构,只是我们的测试文件以扩展名 .TEST 或 .QTEST、.JTEST 结尾,基于测试框架,因为我们有 JavaScript 和其他需要测试的嵌入式代码。因此,我们在目录节点上使用后缀选项,如下所示。

<phpunit>
<testsuites>
    <testsuite name="Your Test Suite Name">
            <directory suffix=".test">.</directory>
    </testsuite>
</testsuites>
</phpunit>

对于 PHP 单元测试 (*.TEST),我们使用以下 PHPUNIT.xml(已针对大小进行了编辑)

<!-- PHPUnit Core Settings -->
<phpunit backupStaticAttributes="false"
     bootstrap="PeriScope-Bootstrap.php"
             ...

    <testsuites>
        <testsuite name="ICAP User Interface Library">
            <directory suffix=".test">lib/.</directory>
        </testsuite>
        <testsuite name="Enterprise Scale Manager">
            <directory suffix=".test">ESM/.</directory>
        </testsuite>
        ...
    </testsuites>

<!-- Add files not covered with tests into Code Coverage Analysis -->
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".class">lib/.</directory>
            <directory suffix=".fn">lib/.</directory>
            <directory suffix=".php">lib/.</directory>
            ...

            <exclude>
                <directory>ExternalLibraries</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        ...
    </logging>
</phpunit>
于 2012-07-24T14:09:27.253 回答