Phpunit启动所有测试或不启动所有测试,忽略配置

Phpunit启动所有测试或不启动所有测试,忽略配置,phpunit,symfony-3.3,Phpunit,Symfony 3.3,我的项目包含两个包,我只想在其中一个包中运行测试。使用了symfony 3.3和phpunit 6.3.0 phpunit.xml.dist <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd" backupGlobals="false"

我的项目包含两个包,我只想在其中一个包中运行测试。使用了symfony 3.3和phpunit 6.3.0

phpunit.xml.dist

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="./src/CoreBundle/Tests/autoloadWithIsolatedDatabase.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_CLASS" value="AppKernel" />
    </php>

    <testsuites>
        <testsuite name="App">
            <directory>src/AppBundle/Tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*Bundle/Tests</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Tests</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Tests</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

src/AppBundle/Tests
src
src/*Bundle/Resources
src/*捆绑/测试
src/*/*捆绑包/资源
src/*/*捆绑/测试
src/*/Bundle/*Bundle/Resources
src/*/Bundle/*Bundle/Tests
项目的设计和结构

此配置将运行来自AppBundle和CoreBundle的所有测试(在第二个配置中没有测试),如果您更改

<directory>src/AppBundle/Tests</directory> 
src/AppBundle/Tests

src/CoreBundle/Tests

那就根本没有测试了。我不明白出了什么问题

让我们从phpunit.xml.dist的配置开始。您定义了一个测试套件:

<testsuites>
    <testsuite name="App">
        <directory>src/AppBundle/Tests</directory>
    </testsuite>
</testsuites>
您的过滤器可以保留在原位,因为src/CoreBundle/Tests实际上不包含测试类,只包含用于测试的帮助程序


现在,您已经将所有测试放在一个大的测试文件夹中,并用bundle分隔,您可能希望在此文件夹中搜索扩展类
PHPUnit\u Framework\u TestCase
。由于PHPUnit 6.0引入了名称空间,因此需要使用
PHPUnit\Framework\TestCase
更新这些名称空间,否则PHPUnit将忽略这些测试。

如果我在tests文件夹的不同文件夹中编写测试,则设置会起作用(
tests/AppBundle
),谢谢您的回复!原则上我这样做了,所有的测试都被移动到tests文件夹中,因为那里有配置工作。
<testsuites>
    <testsuite name="App">
        <directory>src/AppBundle/Tests</directory>
    </testsuite>
</testsuites>
<testsuites>
    <testsuite name="App">
        <directory>tests/</directory>
    </testsuite>
</testsuites>