【问题标题】:Grouping phpunit tests. Launching test from specified directory分组 phpunit 测试。从指定目录启动测试
【发布时间】:2021-06-28 11:18:35
【问题描述】:

我有一个目录 tests 存储我的所有测试。

tests 目录的层次结构

tests->
       ApplicationTests->
       IntegrationTests->
                         Factory->
                         Service->
       UnitTests->

如何仅从 Service 目录而不是整个 tests 目录进行 phpunit 启动测试?我读到了@Groups,但我认为这不是我想要的,如果我不需要编辑配置文件是最好的,但有些方法,从命令行进行。

【问题讨论】:

  • 如果您在网站上浏览一下,您还可以找到一些关于此的建议和 Q/A 风格讨论,例如stackoverflow.com/q/8313283/367456 , stackoverflow.com/a/7961097/367456 甚至是一些关于配置的基本解释:stackoverflow.com/q/19653958/367456
  • @hakre 是的,我找到了类似的解决方案来解决我的问题,但我不明白如何使用它们。只有在我自己解决了它之后,我才明白它实际上是如何工作的。
  • 是的,希望它们能添加到您开始看到的图片中。可能触发我搜索的原因是,在您的回答中,您指的是测试套件(顺便说一句,这很好),并且有一种更零配置的方法,您可以在其中指向文件夹例如,您要执行 ./vendor/bin/phpunit --testdox tests/IntegrationTests/Server 的测试。顺便说一句,它与测试套件兼容,因此您可以选择其中一个。所以也许按文件夹组织可能是最重要的方法。

标签: phpunit


【解决方案1】:

找到了一个相当简单的方法,即使是配置编辑。

phpunit.xml

请参阅:The XML Configuration File Phpunit DocsOrganizing Tests Phpunit Docs<

<testsuite name="Service">
      <directory>tests/IntegrationTests/Service</directory>
</testsuite>

命令行: php ./vendor/bin/phpunit --testdox --testsuite Service

【讨论】:

    猜你喜欢
    • 2010-09-09
    • 2012-05-21
    • 2019-03-09
    • 2012-03-25
    • 2013-11-08
    • 1970-01-01
    • 2012-08-12
    • 2017-07-03
    • 1970-01-01
    相关资源
    最近更新 更多