дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
feat(dotnet): run .NET tests with coverage (#7736)
Run with Coverage now works for `dotnet test` configurations: VSTest projects collect with coverlet.collector, Microsoft.Testing.Platform projects with Microsoft.Testing.Extensions.CodeCoverage (Cobertura output). The runner is chosen from global.json's test.runner and an MSBuild evaluation of the project; a test project without the package gets an Install notification that runs `dotnet add <project> package …`. Each run writes to its own results directory and the reports of every test project are merged (the TRX logger's copies are not counted twice). Cobertura branch flags are read case-insensitively (coverlet writes `True`). The Rust CI job's .NET 10 SDK step now also serves ide-coverage's real-CLI test. Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
ccb73f4efd
коміт
cff33ee70d
31 files changed
+613
-30
No files matched your search
@@ -29,17 +29,18 @@ If the coverage tool is missing, a notification names it and offers **Install**,
|
||||
|
||||
## Supported runtimes
|
||||
|
||||
| Runtime | Configurations | Coverage tool |
|
||||
| ----------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| Rust | `cargo test`, `cargo run`, `cargo nextest` | `cargo llvm-cov` (install `cargo-llvm-cov` and the `llvm-tools-preview` rustup component) |
|
||||
| Go | `go test` | `go test -coverprofile` |
|
||||
| Java / Kotlin (Maven) | Maven configurations that run tests (`test`, `verify`) | JaCoCo Maven plugin goals |
|
||||
| Java / Kotlin (Gradle) | Gradle configurations that run tests (`test`, `check`) | JaCoCo, applied through an init script |
|
||||
| JavaScript / TypeScript | `package.json` test scripts that run vitest or jest (npm, pnpm, yarn, bun) | The runner's own `--coverage` (vitest needs `@vitest/coverage-v8` or `@vitest/coverage-istanbul`) |
|
||||
| Node.js | `node`, `npx`, `tsx`, `ts-node` programs | `c8` |
|
||||
| Python | scripts, modules, pytest | coverage.py (`coverage run --branch`) in the project's interpreter |
|
||||
| Ruby | rspec, minitest, rake, rails and plain scripts | SimpleCov (in the Gemfile for Bundler projects) |
|
||||
| Swift (Xcode) | Xcode test configurations (`xcodebuild test`) | `-enableCodeCoverage YES`, read from the result bundle with `xcrun xccov` |
|
||||
| Runtime | Configurations | Coverage tool |
|
||||
| ----------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
||||
| Rust | `cargo test`, `cargo run`, `cargo nextest` | `cargo llvm-cov` (install `cargo-llvm-cov` and the `llvm-tools-preview` rustup component) |
|
||||
| Go | `go test` | `go test -coverprofile` |
|
||||
| .NET | `dotnet test` configurations | coverlet.collector or Microsoft.Testing.Extensions.CodeCoverage (see [C# and .NET](/en/languages/csharp)) |
|
||||
| Java / Kotlin (Maven) | Maven configurations that run tests (`test`, `verify`) | JaCoCo Maven plugin goals |
|
||||
| Java / Kotlin (Gradle) | Gradle configurations that run tests (`test`, `check`) | JaCoCo, applied through an init script |
|
||||
| JavaScript / TypeScript | `package.json` test scripts that run vitest or jest (npm, pnpm, yarn, bun) | The runner's own `--coverage` (vitest needs `@vitest/coverage-v8` or `@vitest/coverage-istanbul`) |
|
||||
| Node.js | `node`, `npx`, `tsx`, `ts-node` programs | `c8` |
|
||||
| Python | scripts, modules, pytest | coverage.py (`coverage run --branch`) in the project's interpreter |
|
||||
| Ruby | rspec, minitest, rake, rails and plain scripts | SimpleCov (in the Gemfile for Bundler projects) |
|
||||
| Swift (Xcode) | Xcode test configurations (`xcodebuild test`) | `-enableCodeCoverage YES`, read from the result bundle with `xcrun xccov` |
|
||||
|
||||
Not supported:
|
||||
|
||||
|
||||
@@ -133,6 +133,19 @@ Results appear in the test tree of the Run tool window. The IDE asks VSTest for
|
||||
|
||||
See [Testing](/en/guide/testing) for the test tree and rerunning failed tests.
|
||||
|
||||
### Coverage
|
||||
|
||||
**Run with Coverage** works for `dotnet test` configurations, including a single test started from the gutter, and shows the result in the [coverage views](/en/guide/coverage). Each test project needs a collector package:
|
||||
|
||||
| Test runner | Package |
|
||||
| -------------------------- | ------------------------------------------- |
|
||||
| VSTest (the default) | `coverlet.collector` |
|
||||
| Microsoft.Testing.Platform | `Microsoft.Testing.Extensions.CodeCoverage` |
|
||||
|
||||
The xUnit, NUnit and MSTest templates already reference `coverlet.collector`. When the package is missing from the project a configuration tests, a notification offers **Install** (`dotnet add <project> package …`). A configuration that tests a solution isn't checked: projects without the package are left out of the report.
|
||||
|
||||
Each run writes its results to its own temporary directory, so older reports in `TestResults` are never mixed in, and the reports of several test projects are merged. A stopped run shows no coverage. Remove your own `--results-directory` from the test arguments for coverage runs.
|
||||
|
||||
## Debugging
|
||||
|
||||
Running a .NET Project configuration, or a project file from the Project view, with **Debug** builds the project, asks MSBuild for its output assembly (`TargetPath`, in the Debug configuration) and launches it under netcoredbg. If netcoredbg is missing, a notification offers to install it.
|
||||
|
||||
@@ -25,17 +25,18 @@ description: "使用覆盖率运行配置,在编辑器、项目视图和覆盖
|
||||
|
||||
## 支持的运行时
|
||||
|
||||
| 运行时 | 配置 | 覆盖率工具 |
|
||||
| ----------------------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
||||
| Rust | `cargo test`、`cargo run`、`cargo nextest` | `cargo llvm-cov`(需安装 `cargo-llvm-cov` 和 rustup 组件 `llvm-tools-preview`) |
|
||||
| Go | `go test` | `go test -coverprofile` |
|
||||
| Java / Kotlin(Maven) | 运行测试的 Maven 配置(`test`、`verify`) | JaCoCo Maven 插件目标 |
|
||||
| Java / Kotlin(Gradle) | 运行测试的 Gradle 配置(`test`、`check`) | JaCoCo,通过 init 脚本应用 |
|
||||
| JavaScript / TypeScript | 运行 vitest 或 jest 的 `package.json` 测试脚本(npm、pnpm、yarn、bun) | 测试框架自带的 `--coverage`(vitest 需要 `@vitest/coverage-v8` 或 `@vitest/coverage-istanbul`) |
|
||||
| Node.js | `node`、`npx`、`tsx`、`ts-node` 程序 | `c8` |
|
||||
| Python | 脚本、模块、pytest | 项目解释器中的 coverage.py(`coverage run --branch`) |
|
||||
| Ruby | rspec、minitest、rake、rails 和普通脚本 | SimpleCov(Bundler 项目需写在 Gemfile 中) |
|
||||
| Swift(Xcode) | Xcode 测试配置(`xcodebuild test`) | `-enableCodeCoverage YES`,用 `xcrun xccov` 读取结果包 |
|
||||
| 运行时 | 配置 | 覆盖率工具 |
|
||||
| ----------------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
||||
| Rust | `cargo test`、`cargo run`、`cargo nextest` | `cargo llvm-cov`(需安装 `cargo-llvm-cov` 和 rustup 组件 `llvm-tools-preview`) |
|
||||
| Go | `go test` | `go test -coverprofile` |
|
||||
| .NET | `dotnet test` 配置 | coverlet.collector 或 Microsoft.Testing.Extensions.CodeCoverage(见 [C# 与 .NET](/zh/languages/csharp)) |
|
||||
| Java / Kotlin(Maven) | 运行测试的 Maven 配置(`test`、`verify`) | JaCoCo Maven 插件目标 |
|
||||
| Java / Kotlin(Gradle) | 运行测试的 Gradle 配置(`test`、`check`) | JaCoCo,通过 init 脚本应用 |
|
||||
| JavaScript / TypeScript | 运行 vitest 或 jest 的 `package.json` 测试脚本(npm、pnpm、yarn、bun) | 测试框架自带的 `--coverage`(vitest 需要 `@vitest/coverage-v8` 或 `@vitest/coverage-istanbul`) |
|
||||
| Node.js | `node`、`npx`、`tsx`、`ts-node` 程序 | `c8` |
|
||||
| Python | 脚本、模块、pytest | 项目解释器中的 coverage.py(`coverage run --branch`) |
|
||||
| Ruby | rspec、minitest、rake、rails 和普通脚本 | SimpleCov(Bundler 项目需写在 Gemfile 中) |
|
||||
| Swift(Xcode) | Xcode 测试配置(`xcodebuild test`) | `-enableCodeCoverage YES`,用 `xcrun xccov` 读取结果包 |
|
||||
|
||||
暂不支持:
|
||||
|
||||
|
||||
@@ -112,6 +112,19 @@ C# 在装了 Roslyn 语言服务器时用它,否则用 csharp-ls。Roslyn 是
|
||||
|
||||
测试树和重新运行失败测试等内容见[测试](/zh/guide/testing)。
|
||||
|
||||
### 覆盖率
|
||||
|
||||
`dotnet test` 配置支持**带覆盖率运行**(包括从行号栏运行单个测试),结果显示在[覆盖率视图](/zh/guide/coverage)中。每个测试项目都需要一个收集器包:
|
||||
|
||||
| 测试运行器 | 包 |
|
||||
| -------------------------- | ------------------------------------------- |
|
||||
| VSTest(默认) | `coverlet.collector` |
|
||||
| Microsoft.Testing.Platform | `Microsoft.Testing.Extensions.CodeCoverage` |
|
||||
|
||||
xUnit、NUnit 和 MSTest 模板默认已引用 `coverlet.collector`。如果配置所测试的项目缺少对应的包,会弹出带**安装**按钮的通知(执行 `dotnet add <项目> package …`)。测试解决方案的配置不做检查:没有引用包的项目不会出现在报告中。
|
||||
|
||||
每次运行的结果写入单独的临时目录,因此不会混入 `TestResults` 里的旧报告;多个测试项目的报告会合并。中途停止的运行不显示覆盖率。带覆盖率运行前,请从测试参数中去掉自己指定的 `--results-directory`。
|
||||
|
||||
## 调试
|
||||
|
||||
以 **调试** 方式运行 .NET 项目配置或项目视图中的项目文件时,IDE 会先构建项目,再向 MSBuild 查询输出程序集(Debug 配置下的 `TargetPath`),然后在 netcoredbg 下启动。缺少 netcoredbg 时会弹出通知提供安装。
|
||||
|
||||
Reference in new issue
Заблокувати користувача