-
Notifications
You must be signed in to change notification settings - Fork 381
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
Draft
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/add-code-coverage-targets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fd6abb4
Initial plan
Copilot 76eecbb
Add code coverage support to Arcade SDK with VSTest integration
Copilot 4703bcb
Fix runsettings generation to use ItemGroup for proper XML formatting
Copilot 02a26bd
Add code coverage example documentation
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Code Coverage Example for Arcade SDK | ||
|
||
This example demonstrates how to enable code coverage collection in test projects using Arcade SDK. | ||
|
||
## Prerequisites | ||
|
||
- Arcade SDK 11.0.0 or later | ||
- Test project using XUnit | ||
|
||
## Basic Configuration | ||
|
||
Add the following properties to your test project file: | ||
|
||
```xml | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<!-- Enable VSTest runner instead of XUnit console runner --> | ||
<UseVSTestRunner>true</UseVSTestRunner> | ||
|
||
<!-- Enable code coverage collection --> | ||
<CollectCoverage>true</CollectCoverage> | ||
|
||
<!-- Optional: Specify coverage format (default is cobertura) --> | ||
<CodeCoverageFormat>cobertura</CodeCoverageFormat> | ||
</PropertyGroup> | ||
</Project> | ||
``` | ||
|
||
## Running Tests with Coverage | ||
|
||
Run tests using the build script: | ||
|
||
```bash | ||
./build.sh --test | ||
``` | ||
|
||
Or using MSBuild directly: | ||
|
||
```bash | ||
dotnet build /t:Test /p:Configuration=Release | ||
``` | ||
|
||
## Coverage Reports | ||
|
||
Code coverage reports will be generated in the `artifacts/TestResults/coverage/` directory. | ||
|
||
For Cobertura format, the report file will be named `coverage.cobertura.xml` and can be published to Azure DevOps. | ||
|
||
## Azure DevOps Integration | ||
|
||
Add the following task to your Azure Pipelines YAML to publish coverage results: | ||
|
||
```yaml | ||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: '$(Build.SourcesDirectory)/artifacts/TestResults/coverage/**/coverage.cobertura.xml' | ||
codecoverageTool: 'cobertura' | ||
displayName: 'Publish Code Coverage Results' | ||
``` | ||
|
||
## Advanced Configuration | ||
|
||
### Filtering Coverage | ||
|
||
Exclude specific assemblies or files from coverage: | ||
|
||
```xml | ||
<PropertyGroup> | ||
<!-- Exclude test assemblies and external dependencies --> | ||
<CoverageExclude>[*.Tests]*;[xunit.*]*;[Moq]*</CoverageExclude> | ||
|
||
<!-- Exclude generated files --> | ||
<CoverageExcludeByFile>**/*Designer.cs;**/Generated/*.cs</CoverageExcludeByFile> | ||
|
||
<!-- Exclude obsolete code --> | ||
<CoverageExcludeByAttribute>Obsolete;GeneratedCode;CompilerGenerated</CoverageExcludeByAttribute> | ||
</PropertyGroup> | ||
``` | ||
|
||
### Multiple Output Formats | ||
|
||
Generate coverage in multiple formats: | ||
|
||
```xml | ||
<PropertyGroup> | ||
<CodeCoverageFormat>cobertura,opencover,lcov</CodeCoverageFormat> | ||
</PropertyGroup> | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
### Coverage not collected | ||
|
||
- Ensure `UseVSTestRunner` is set to `true` | ||
- Verify `CollectCoverage` is set to `true` | ||
- Check that `coverlet.collector` package is restored (should be automatic) | ||
|
||
### Empty coverage report | ||
|
||
- Make sure tests are actually running and passing | ||
- Verify the test project has a reference to the code you want to cover | ||
|
||
## See Also | ||
|
||
- [Arcade SDK Documentation](../Documentation/ArcadeSdk.md) | ||
- [Coverlet Documentation](https://github.com/coverlet-coverage/coverlet) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.