当我运行包含覆盖范围的 PHPUnit 套件时,我在生成的 HTML 中得到以下内容:
Legend
Low: 0% to 50% Medium: 50% to 90% High: 90% to 100%
Generated by PHP_CodeCoverage 2.0.13 using PHP 5.5.9-1ubuntu4.5 and PHPUnit 4.4.0 at Sun Dec 21 20:21:31 UTC 2014.
Run Code Online (Sandbox Code Playgroud)
50% 和 90%“切换点”是否可配置(这样我可以分别更改为 35% 和 75%)?如何?
构建工具:Maven
使用离线检测的原因:删除 Powermock 不是一个选项
问题:failsafe 和 Surefire 均运行并生成报告。但是,jacoco.exec 是生成的,但 jacoco-it.exec 不是。除了 IT 之外,离线检测、覆盖范围和报告也运行良好。
这是我使用的 Maven 插件配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
为了运行测试,我使用 Maven clean install。 …
我正在努力实现 100% 的代码覆盖率。然而,不知何故,代码覆盖率抱怨某些未覆盖的 MoveNext() 方法,但是,没有迭代 IEnumerable 的代码路径...
关于如何覆盖 MoveNext 方法有什么想法吗?MoveNext() 位于哪里?
最近我为我的项目解决方案创建了单元测试方法。当我进行代码分析以找出代码覆盖率时,它显示 82% 的代码覆盖率。
但是当我在 TFS 上检查代码时,构建服务器代码分析报告显示代码覆盖率为 58%。
请问有人可以告诉我他们是否遇到过这个问题或有任何可能的解决方案吗?
code-coverage tfsbuild vs-unit-testing-framework visual-studio-2017
我第一次尝试将 C++ 中的覆盖范围与 clang 6 集成,并且一直在遵循本指南。
\n\n我成功编译了二进制文件,生成了一个.profraw文件,并.profdata按照步骤 1、2 和 3a 中所述生成了一个文件。但是,当我尝试创建 3b 中所述的面向行的覆盖率报告时,我收到以下消息:
error: build/debug/dane: Failed to load coverage: No coverage data found\nRun Code Online (Sandbox Code Playgroud)\n\n检查.profraw文件后,我发现它是空的。我尝试稍微更改一下代码并再次运行,但生成的代码.profraw始终为空。
我的main.cpp文件:
error: build/debug/dane: Failed to load coverage: No coverage data found\nRun Code Online (Sandbox Code Playgroud)\n\n我的SConstruct文件:
#include <iostream>\n\nint main(int argc, char **argv) {\n std::cout << "Hello, World!" << std::endl;\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n命令行输出:
\n\n\nenv = Environment(CXX=\'clang++\', CXXFLAGS=[\'-Wall\', \'-g\', …Run Code Online (Sandbox Code Playgroud) 我想展示使用 Gradle 6.0 构建的多个项目 Spring boot 应用程序的测试覆盖率。我们目前使用 JUnit5。
尽管存在一些初步测试,SonarQube 中的测试覆盖率显示为 0%。
顶级项目(https://github.com/OpenReqEU/eclipse-plugin-vogella/blob/master/server/build.gradle)中的 build.gradle 文件具有以下输入:
plugins {
id "org.sonarqube" version "2.7"
id 'jacoco'
}
repositories {
jcenter()
}
subprojects {
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
jcenter()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
jacocoTestReport {
reports {
xml.enabled true
xml.destination file("${buildDir}/coverage-reports/coverage.xml")
//html.destination file("${buildDir}/coverage-reports")
}
}
ext {
springBootVersion = …Run Code Online (Sandbox Code Playgroud) 这是一个非常基本的问题,应该有一个简单的解决方案。我希望将单元测试项目的所有代码覆盖率结果放在解决方案中以输出到单个目录中。目前,所有覆盖率输出文件都被写入各个测试项目文件夹中。我尝试研究 coverlet github 问题,其中他们提到他们有一种解决方法(https://github.com/tonerdo/coverlet/pull/220),可以将所有覆盖文件合并到一个文件中,但我无法不要将它们放入我的解决方案目录中
dotnet test .\MySolution.sln /p:CollectCoverage=true /p:CoverletOutput=/results/coverage /p:MergeWith=\results\coverage.json /p:CoverletOutputFormat='json%2copencover'
Run Code Online (Sandbox Code Playgroud)
我正在努力的是在参数中指定解决方案目录/p:CoverletOutput。dotnet cli 中是否有一个特殊参数来指向类似于 msbuild 中的解决方案目录$(MSBuildProjectDirectory)?
我正在开发一个新项目,其中客户预先存在的生产代码覆盖率低,只有 72%,因此我无法部署在沙箱中完成的任何工作。
错误:
代码覆盖率失败您的代码覆盖率为 72%。您需要至少 75% 的覆盖率才能完成此部署。
有没有人有关于如何增加代码覆盖率的建议?
我有一个 .net core 项目,在 Azure DevOps 中设置了管道(YAML、多阶段)管道。我们有一堆在管道运行时执行的单元测试 - 一切都很好。
然而,我们希望更深入地了解我们的代码覆盖率。所以我们这样配置我们的任务
- task: DotNetCoreCLI@2
displayName: Run UnitTests
enabled: true
inputs:
command: test
projects: '**/PM.UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
Run Code Online (Sandbox Code Playgroud)
结果是这样的
我们现在可以在管道结果中看到这一点:
可以在 Visual Studio 等中下载并分析该 .coverage 文件。
然而,我们真的希望能够直接在 Azure Pipelines 中看到结果。我们有一个 Typescript 项目来执行此操作。结果是这样的:

遗憾的是,我根本不知道如何将其应用到 .net core 项目。
Q1:.net core 项目是否有可能获得相同的体验……以及如何获得?
此外,我们希望能够对用于计算代码覆盖率百分比的代码部分进行过滤。
问题 2:是否正确理解这是使用.runsettings文件完成的?
谢谢 :-)
/杰斯珀
作为参考,这是我的测试 .net core 解决方案中的完整 YAML 管道。解决方案超级简单——一个.net core类库和一个.net core测试类库
pool:
vmImage: vs2017-win2016
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
feedsToUse: 'select'
vstsFeed: 'd12c137f-dac4-4ea7-bc39-59bd2b784537' …Run Code Online (Sandbox Code Playgroud) code-coverage .net-core azure-pipelines azure-pipelines-yaml
我有一个带有大量测试的 Laravel 项目。我使用 pcov 来计算代码覆盖率,大约需要 4 分钟。但 pcov 不支持分支覆盖,所以我决定使用 xdebug。
使用 xdebug 测试执行,使用代码覆盖率但不使用 --path-coverage(分支覆盖率)大约需要 8 分钟。
但是使用 xdebug、代码覆盖率和 --path-coverage(分支覆盖率)测试执行需要超过 2 个小时,甚至不能等到结束:
INFO[2021-09-14 21:33:24] Executing runtests with coverage xdebug
XDEBUG_MODE=coverage
php artisan test --parallel --processes=8 --verbose --passthru=--path-coverage tests/Feature --coverage-text
Warming cache for static analysis ... done [00:00.071]
............S................................................ 61 / 1180 ( 5%)
............................................................. 122 / 1180 ( 10%)
............................................................. 183 / 1180 ( 15%)
............................................................. 244 / 1180 ( 20%)
.......
INFO[2021-09-15 00:00:05] finished in 2h 26m 40.458565176s
Run Code Online (Sandbox Code Playgroud)
所以我的问题是 --path-coverage …
code-coverage ×10
c# ×2
jacoco ×2
phpunit ×2
unit-testing ×2
.net ×1
.net-core ×1
apex ×1
c++ ×1
clang++ ×1
coverlet ×1
dotnet-cli ×1
gradle ×1
jenkins ×1
llvm-clang ×1
maven ×1
salesforce ×1
sonarqube ×1
tfsbuild ×1
xdebug ×1