这是我用 Codeception (GitHub 上的项目) 进行远程代码覆盖测试的配置。
远程代码覆盖收集步骤
1. 确保已安装并启用 Xdebug。
2. 配置 Codeception。
文件 codeception.yml
(GitHub):
coverage:
enabled: true
c3_url: 'http://%SERVICE_HOST%/index-test.php/'
include:
- web/*
- config/*
- src/*
3. 启用你需要的测试套件覆盖率。
文件 acceptance.suite.yml
(GitHub):
coverage:
remote: true
在我的例子中,它仅在验收测试中启用。
4. 在您的应用程序引导文件中包含c3.php
文件。
应用程序引导文件 index-test.php
(GitHub):
// Start the remote code coverage collection.
require_once __DIR__.'/../c3.php';
// autoloader, application running and etc
// ...
5. 运行覆盖率测试。
$ vendor/bin/codecept run --coverage --coverage-html
默认情况下,您可以在tests/_output
目录中找到您的报告。
可能出现的问题
1. 输出目录不可写 (tests/_output
)。
$ chmod 777 tests/_output
2. 远程代码覆盖率未在控制台中打印。
不应该被打印。根据文档:
coverage:
remote: true
In this case remote Code Coverage results won’t be merged with local ones, if this option is enabled. Merging is possible only in case a remote and local files have the same path. But in case of running tests on a remote server we are not sure of it.
3. 其他错误。
尝试启用调试。如果启用了调试,您可以获取报告或清除它。
curl -o codecoverage.tar "http://localhost:8080/index-test.php/c3/report/html"
结束
有时候这并不是一项微不足道的任务。因此,我希望这可以帮到您!