代码覆盖率在GitLab中始终未知

问题描述 投票:1回答:1

我正在尝试理解GitLab管道,经过几次尝试后,我能够成功地自动化我的单元测试。现在我正在尝试将代码覆盖徽章添加到我的项目和/或自述文件中,但似乎总是显示unknown

文件:

+ application
+ system
- unit-tests
  - tests
      UtilTest.php
    autoload.php
    phpunit
  .gitignore
  .gitlab-ci.yml
  .htaccess
  index.php
  readme.md

.gitlab-ci.yml:

image: php:5.6

stages:
  - test

app:unit-tests:
  stage: test
  script:
    - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests
  coverage: '/Code Coverage: \d+\.\d+/'

在项目的Test coverage parsing部分,我有这个设置:enter image description here

如果您需要更多信息,请告诉我,我会将它们添加进去。感谢所有帮助,谢谢!

unit-testing gitlab code-coverage gitlab-ci gitlab-ci-runner
1个回答
1
投票

所以我能够通过使用PHP 7.2作为Docker镜像并在xdebug调用上安装before_script来解决这个问题。

.gitlab-ci.yml:

image: php:7.2

stages:
  - test

before_script:
  - pecl install xdebug
  - docker-php-ext-enable xdebug

app:unit-tests:
  stage: test
  script:
  - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests --coverage-text --colors=never
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'

我不得不使用PHP 7.2,因为当我尝试运行pecl install xdebug时它说它需要PHP 7.理想情况下我想使用PHP 5.6,因为这是我们当前的服务器刚刚所以测试是在类似的版本,但我会留下它,因为它现在是。

我不得不在--coverage-text --colors=never上添加script,以便输出数字。然后在coverage调用我改为'/^\s*Lines:\s*\d+.\d+\%/',我也在项目设置的Test coverage parsing部分使用。

现在,代码覆盖率正确地显示了我的预期值。

© www.soinside.com 2019 - 2024. All rights reserved.