如何设置带远程代码覆盖率的Codeception?

17
  • 我在我的电脑上有两个代码库
    1. API
    2. 测试API的Codeception代码库

    我已经将codeception+c3添加到API代码库中。

"require-dev": {
    "codeception/codeception": "2.*",
    "codeception/c3": "2.*",

我也将c3.php包含在index.php中,但是在使用--coverage测试时,我遇到了以下错误:

[PHPUnit_Framework_Exception] file_get_contents(http://local.api.codeception.com/c3/report/clear): fai led to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

是否有任何关于使用Codeception进行远程代码覆盖的在线示例?


1
好的,我不懒,所以我创建了一个带有API和Codeception测试的小型repo。 真的不知道如何正确设置YML。https://github.com/Horki/remotecoverage - Ivan Z. Horvat
1
你尝试过在C3中显示发生的错误吗?在包含c3.php之前,你可以使用"define('C3_CODECOVERAGE_ERROR_LOG_FILE', '/path/to/c3_error.log');"设置一个常量(请参见https://github.com/Codeception/c3#setup)。在文件中,你应该能看到为什么会出现500结果的错误。 - NiMeDia
可能会有帮助的类似错误和问题:https://github.com/Codeception/Codeception/issues/655 - desc
2个回答

2

这是我用 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"

结束

有时候这并不是一项微不足道的任务。因此,我希望这可以帮到您!


1

好的,这是一个配置噩梦,但我已经解决了

这里 是例子


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接