PHPUnit + Sonarqube 导出的覆盖范围与实际 xml 结果不匹配
PHPUnit + Sonarqube exported coverage do not match with actual xml result
声纳库:5.1.2
声纳-运行纳尔:2.2.1
php插件:2.6
PHPUnit 4.2.6
我们正在 运行宁 php我们的应用程序,但我无法按预期获得正确的声纳覆盖率百分比。
在我的 phpunit.xml 中,我们有过滤器定义我们只想覆盖的文件夹。
<whitelist addUncoveredFilesFromWhitelist="false">
<directory>./site-library-php/src/main/php/BabelCentral/Model/Content</directory>
</whitelist>
在我的声纳属性中
sonar.modules=php-module
php-module.sonar.phpUnit.coverage.analyzeOnly=true
php-module.sonar.phpUnit.analyzeOnly=true
php-module.sonar.php.tests.reportPath=site-main-php/src/test/target/reports/phpunit.xml
php-module.sonar.php.coverage.reportPath=site-main-php/src/test/target/reports/phpunit.coverage.xml
查看 jenkins 上的日志,测试似乎 运行 正常并以:
结尾
Tests: 1479, Assertions: 4165, Failures: 58, Incomplete: 14, Skipped: 55.
Generating code coverage report in Clover XML format ... done
Generating code coverage report in HTML format ... done
// further down
11:47:51.973 INFO - Analyzing PHPUnit test report: site-main-php/src/test/target/reports/phpunit.xml with org.sonar.plugins.php.phpunit.PhpUnitResultParser@35e7e715
11:47:52.604 INFO - Analyzing PHPUnit unit test coverage report: site-main-php/src/test/target/reports/phpunit.coverage.xml with PHPUnit Unit Test Coverage Result Parser
似乎一切正常。但是,sonar 会报告不同的结果,覆盖整个源文件夹。这些是仪表板上显示的数字。
Unit Tests Coverage 1.8%
line coverage 1.8%
Unit test success 95.9%
有声纳尊重php单位配置的过滤器吗?
注意:
如果我明确设置
,我就能达到所需的覆盖率
php-module.sonar.sources
到我想要的directories/files。只是,逗号分隔的配置比 phpunit 的 xml 配置难管理。
定义应由 SonarQube 分析的源文件集至关重要:正是在这组文件上应用了编码规则并计算了指标。
sonar.sources
因此是强制性的 属性 并且是配置源文件集的主要方式。
其他属性可用于优化源文件集:
- 您可以配置
sonar.tests
:测试文件自动从sonar.sources
中排除。
- 您可能必须排除一些其他 PHP 文件,例如依赖关系或使用
sonar.exclusions
生成的代码。
您还应该知道几个插件可能有助于项目的全球覆盖:如果您安装了 JavaScript 插件并且如果 sonar.sources
包含 JavaScript 文件,它们将在计算覆盖率指标时也会考虑在内。
如果您只对调整覆盖率感兴趣,可以使用 sonar.coverage.exclusions
.
从覆盖率指标中排除文件
声纳库:5.1.2 声纳-运行纳尔:2.2.1 php插件:2.6 PHPUnit 4.2.6
我们正在 运行宁 php我们的应用程序,但我无法按预期获得正确的声纳覆盖率百分比。
在我的 phpunit.xml 中,我们有过滤器定义我们只想覆盖的文件夹。
<whitelist addUncoveredFilesFromWhitelist="false">
<directory>./site-library-php/src/main/php/BabelCentral/Model/Content</directory>
</whitelist>
在我的声纳属性中
sonar.modules=php-module
php-module.sonar.phpUnit.coverage.analyzeOnly=true
php-module.sonar.phpUnit.analyzeOnly=true
php-module.sonar.php.tests.reportPath=site-main-php/src/test/target/reports/phpunit.xml
php-module.sonar.php.coverage.reportPath=site-main-php/src/test/target/reports/phpunit.coverage.xml
查看 jenkins 上的日志,测试似乎 运行 正常并以:
结尾Tests: 1479, Assertions: 4165, Failures: 58, Incomplete: 14, Skipped: 55.
Generating code coverage report in Clover XML format ... done
Generating code coverage report in HTML format ... done
// further down
11:47:51.973 INFO - Analyzing PHPUnit test report: site-main-php/src/test/target/reports/phpunit.xml with org.sonar.plugins.php.phpunit.PhpUnitResultParser@35e7e715
11:47:52.604 INFO - Analyzing PHPUnit unit test coverage report: site-main-php/src/test/target/reports/phpunit.coverage.xml with PHPUnit Unit Test Coverage Result Parser
似乎一切正常。但是,sonar 会报告不同的结果,覆盖整个源文件夹。这些是仪表板上显示的数字。
Unit Tests Coverage 1.8%
line coverage 1.8%
Unit test success 95.9%
有声纳尊重php单位配置的过滤器吗?
注意: 如果我明确设置
,我就能达到所需的覆盖率php-module.sonar.sources
到我想要的directories/files。只是,逗号分隔的配置比 phpunit 的 xml 配置难管理。
定义应由 SonarQube 分析的源文件集至关重要:正是在这组文件上应用了编码规则并计算了指标。
sonar.sources
因此是强制性的 属性 并且是配置源文件集的主要方式。
其他属性可用于优化源文件集:
- 您可以配置
sonar.tests
:测试文件自动从sonar.sources
中排除。 - 您可能必须排除一些其他 PHP 文件,例如依赖关系或使用
sonar.exclusions
生成的代码。
您还应该知道几个插件可能有助于项目的全球覆盖:如果您安装了 JavaScript 插件并且如果 sonar.sources
包含 JavaScript 文件,它们将在计算覆盖率指标时也会考虑在内。
如果您只对调整覆盖率感兴趣,可以使用 sonar.coverage.exclusions
.