每次我运行一个类或整个文件夹的单元测试时,PHPunit会为整个系统生成覆盖,因为它是在PHPunit.xml中配置的.
这很糟糕,因为它需要更长的时间并耗尽 PHP的内存.
这很糟糕,因为它需要更长的时间并耗尽 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手册:
原文链接:https://www.f2er.com/php/136890.htmlThe @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
这对你的场景有用吗?