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]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-12-05 09:51:24 +08:00
1 джерело ccb73f4efd
коміт cff33ee70d
31 files changed
+613 -30

No files matched your search

+5
Переглянути файл
@@ -7319,6 +7319,11 @@ export type CoverageReportSpec =
{ kind: "simpleCov"; path: IpcPath; base: IpcPath } |
/** Every JaCoCo XML report (Maven `target/site/jacoco`, Gradle `build/reports/jacoco`) under `dir`. */
{ kind: "jacoco"; dir: IpcPath } |
/**
* The Cobertura reports `dotnet test` left in its results directory `dir`: one per test
* project and target framework. `hint` explains why there might be none.
*/
{ kind: "cobertura"; runner: string; dir: IpcPath; base: IpcPath; hint: string } |
/** The tool's raw data is exported to lcov by `argv` first (coverage.py: `… -m coverage lcov -o <lcov>`). */
{ kind: "exported"; runner: string; argv: string[]; cwd: IpcPath; env: { [key in string]: string }; lcov: IpcPath } |
/** An Xcode result bundle, read with `xcrun xccov`; only files under `root` are kept. */
+2
Переглянути файл
@@ -46,6 +46,8 @@ const suite = (files: FileCoverage[]): CoverageSuite => ({ runner: "t", hasBranc
describe("coverageSupports", () => {
it("knows the coverage runners", () => {
expect(coverageSupports(cfg("cargo", ["test"]))).toBe(true);
expect(coverageSupports(cfg("dotnet", ["test", "T.csproj"]))).toBe(true);
expect(coverageSupports(cfg("dotnet", ["run"]))).toBe(false);
expect(coverageSupports(cfg("cargo", ["+nightly", "run"]))).toBe(true);
expect(coverageSupports(cfg("cargo", ["build"]))).toBe(false);
expect(coverageSupports(cfg("go", ["test", "./..."]))).toBe(true);
+2
Переглянути файл
@@ -29,6 +29,8 @@ export function coverageSupports(config: Pick<RunConfig, "command" | "args" | "k
}
case "go":
return args[0] === "test";
case "dotnet":
return config.kind === "dotnet-test" || args[0] === "test";
case "mvn":
case "mvnw":
case "gradle":
+5
Переглянути файл
@@ -231,6 +231,11 @@ export const dotnetTestType: RunConfigTypeContribution = {
const boundary = extra.indexOf("--");
extra.splice(boundary < 0 ? extra.length : boundary, 0, ...selection);
}
// Run with Coverage: VSTest options go before `--` (RunSettings), testing-platform ones at the end.
if (p.coverageArgs) {
const boundary = !p.runner || p.runner === "vstest" ? extra.indexOf("--") : -1;
extra.splice(boundary < 0 ? extra.length : boundary, 0, ...(JSON.parse(p.coverageArgs) as string[]));
}
return {
...line,
args: [...line.args, ...(p.runner === "mtp-legacy" && extra[0] !== "--" ? ["--"] : []), ...extra],
+7
Переглянути файл
@@ -33,6 +33,13 @@ describe(".NET workspace formats and runners", () => {
expect(line.args.indexOf("--no-build")).toBeLessThan(line.args.indexOf("--"));
expect(line.args.slice(line.args.indexOf("--") + 1)).toEqual(["--filter", "FullyQualifiedName=A.Tests.Two"]);
});
it.each([
["vstest", ["--cov", "--", "A=1"]],
["mtp", ["--", "A=1", "--cov"]],
])("places %s coverage arguments", (runner, tail) => {
const p = { project: project.path, runner, programArgs: "-- A=1", coverageArgs: '["--cov"]' };
expect(dotnetTestType.commandLine(p)!.args.slice(-3)).toEqual(tail);
});
it("resolves solution projects, XML entities and external references", () => {
expect(
solutionPaths(