-
Notifications
You must be signed in to change notification settings - Fork 382
Add code coverage support to Arcade SDK with VSTest integration #16206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: rmarinho <[email protected]>
Co-authored-by: rmarinho <[email protected]>
Co-authored-by: rmarinho <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code should probably ensure that coverlet NuGet package is installed (or at least assume that some property linked to enabling this feature is linked to enabling coverlet).
Note that we probably should also support Microsoft Code Coverage and MTP.
cc @Youssef1313
|
||
<!-- Add coverlet.collector package when code coverage is enabled and using VSTest --> | ||
<ItemGroup Condition="'$(IsTestProject)' == 'true' and '$(CollectCoverage)' == 'true' and '$(UseVSTestRunner)' == 'true'"> | ||
<PackageReference Include="coverlet.collector" IsImplicitlyDefined="true" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's very possible to install coverlet.msbuild
instead, and have that working both for VSTest and MTP.
winforms and wpf are both already using coverlet.msbuild with MTP IIRC. But coverlet.msbuild won't work with dotnet test
+ MTP. It will only work with Arcade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a CodeCoverageTool
MSBuild property that can either be left empty (no coverage), or be set to either coverlet or MS.CC.
Additionally, we could have CodeCoverageMode
that can be MSBuild
, PlatformExtension
, or GlobalTool
, taking into considerations that not all modes are supported in all scenarios, and unsupported scenarios need to be handled by producing an error. For example, there is no PlatformExtension for coverlet when using MTP.
Summary
This PR implements comprehensive code coverage support for Arcade SDK test projects using VSTest and coverlet.collector, addressing issue #1027.
Problem
The original issue highlighted that the current XUnit test runner implementation (
dotnet exec $(TestRunnerPath)
) prevents using packages likecoverlet.msbuild
for code coverage collection. Repositories using Arcade SDK had no built-in way to collect and report code coverage, making it difficult to measure test effectiveness and integrate with Azure DevOps pipelines.Solution
This PR adds native code coverage support by leveraging:
UseVSTestRunner
propertyUsage
Enable code coverage in your test project with just two properties:
Then run tests normally:
Coverage reports are automatically generated in
artifacts/TestResults/coverage/
in Cobertura format (configurable).Features
Code Coverage Properties
All properties are optional with sensible defaults:
CollectCoverage
- Enable/disable coverage (default:false
)CodeCoverageFormat
- Output format:cobertura
,opencover
,lcov
,json
, or combinations (default:cobertura
)CodeCoverageOutputDirectory
- Where to save reports (default:$(ArtifactsTestResultsDir)coverage
)CoverageDeterministic
- Deterministic reports (default:true
)CoverageInclude
- Assemblies to include (glob patterns)CoverageExclude
- Assemblies to exclude (glob patterns)CoverageIncludeByFile
- Files to include (glob patterns)CoverageExcludeByFile
- Files to exclude (glob patterns)CoverageExcludeByAttribute
- Attributes to excludeAdvanced Example
Azure DevOps Integration
The Cobertura format is natively supported by Azure DevOps. Add this task to your pipeline:
Technical Details
Implementation
coverlet.collector
package reference when coverage is enabledCollectCoverage
metadata toTestToRun
items--collect:"XPlat Code Coverage"
to the test command and generates .runsettings file with coverage configurationAutomatic .runsettings Generation
When
CollectCoverage=true
and no custom.runsettings
file is specified, the build automatically generates one with:Backward Compatibility
Documentation
Added comprehensive documentation:
Testing
Addresses Issue #1027
This implementation provides:
coverlet.msbuild
)Fixes #1027
Original prompt
Fixes #1946
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.