2017-08-16 78 views
0

我的项目包含2个软件包,我只想在其中一个测试中运行测试。使用symfony的3.3PHPUnit的6.3.0Phpunit启动所有测试或不启动所有测试,忽略配置

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> 

和结构工程

structure

此配置将运行所有测试AppBundle和CoreBundle(在第二个没有测试),如果你改变

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

<directory>src/CoreBundle/Tests</directory> 

则会有完全没有测试。我不明白什么是错的

+0

如果我在测试文件夹中的不同文件夹中写入测试 - 设置工作('测试/ AppBundle') –

回答

1

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

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

这是phpunit将考虑进行测试的地方。他们必须符合惯例,例如文件名以Test结尾,每种测试方法必须以test作为前缀。

也可以从你的屏幕截图中了解到,你有一个顶级测试/文件夹(就在app /,src /等旁边)。这可能是你的其他测试都放在

第二个文件夹是你也应该把你的测试从的appbundle如果你遵循的最佳做法:https://symfony.com/doc/current/best_practices/tests.html

我认为这是3的某个时候成立.x发布周期。

从理论上讲,你应该能够将src/AppBundle/Tests复制到测试/ AppBundle,并且希望所有东西都能正常工作。现在,您可以更新您的测试套件配置:

<testsuites> 
    <testsuite name="App"> 
     <directory>tests/</directory> 
    </testsuite> 
</testsuites> 

您的过滤器可以留在地方作为SRC/CoreBundle /测试实际上并不包含测试类,仅用于测试的帮手。

现在您已经将一个大型测试文件夹中的所有测试分为多个包,您可能需要在此文件夹中搜索延伸到PHPUnit_Framework_TestCase的类。由于PHPUnit 6.0引入了名称空间,因此需要使用PHPUnit\Framework\TestCase进行更新,否则PHPUnit将忽略这些测试。

+0

感谢您的回复!原则上我这样做了,所有的测试都被移到了测试文件夹中,因为There配置工作。 –