gpt4 book ai didi

php - 仅生成刚刚测试的内容的覆盖范围

转载 作者:可可西里 更新时间:2023-11-01 12:38:37 24 4
gpt4 key购买 nike

每次我运行一个类或整个文件夹的单元测试时,phpunit 都会生成整个系统的覆盖范围,因为它是在 phpunit.xml 中配置的。
这很糟糕,因为它需要更长的时间并耗尽 PHP 的内存。

我的 phpunit.xml

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "Bootstrap.php" >

<testsuites>
<testsuite name="Application Module Suite Test">
<directory>./Module1Test</directory>
<directory>./Module2Test</directory>
<directory>./Module3Test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>../module/Module1</directory>
<directory>../module/Module2</directory>
<directory>../module/Module3</directory>
</whitelist>
</filter>

</phpunit>

有没有办法动态只覆盖我现在正在测试的内容?

例子
对于下面的命令,我只想为 Controller/ExampleController.php 路径生成覆盖。

phpunit Controller/ExampleController.php --coverage-html ~/Desktop/tests

我使用的是 PHPUnit 4.8 和 3.7,Sublime Text Editor,应用程序使用的是 Zend Framework 2。

最佳答案

来自 PHPUnit 5.6 版手册:

The @covers annotation (see Table B.1) can be used in the test code to specify which method(s) a test method wants to test. If provided, only the code coverage information for the specified method(s) will be considered. Example 11.2 shows an example.

有关示例,请参见此链接:https://phpunit.de/manual/current/en/code-coverage-analysis.html#code-coverage-analysis.specifying-covered-methods.examples.BankAccountTest.php

这对您的场景有用吗?

关于php - 仅生成刚刚测试的内容的覆盖范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40290903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com