-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from jakubch1/main
Add scenario 4 for testing platform and fix reports
- Loading branch information
Showing
17 changed files
with
359 additions
and
200 deletions.
There are no files selected for viewing
This file contains 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,44 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
|
||
name: "Algorithms Scenario 04" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Algorithms/tests/**', 'samples/Algorithms/src/**', '.github/workflows/Algorithms_Scenario04.yml' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Algorithms/tests/Algorithms.Core.Tests | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Test | ||
run: dotnet-coverage collect --output $GITHUB_WORKSPACE/report.cobertura.xml --output-format cobertura "dotnet run --no-build" | ||
- name: ReportGenerator | ||
uses: danielpalme/[email protected] | ||
with: | ||
reports: '${{ github.workspace }}/report.cobertura.xml' | ||
targetdir: '${{ github.workspace }}/coveragereport' | ||
reporttypes: 'MarkdownSummaryGithub' | ||
- name: Upload coverage into summary | ||
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: code-coverage-report | ||
path: ${{ github.workspace }}/report.cobertura.xml |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 1 addition & 69 deletions
70
samples/Algorithms/scenarios/scenario01/example.report.cobertura.xml
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 1 addition & 69 deletions
70
samples/Algorithms/scenarios/scenario02/example.report.cobertura.xml
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,106 @@ | ||
# Scenario Description | ||
|
||
Collect code coverage using `dotnet-coverage` tool for MSTest runner project. | ||
|
||
> **_NOTE:_** MSTest runner project coverage extension by default is not collecting native code coverage. If you want to enable please set to `True` `EnableStaticNativeInstrumentation` or `EnableDynamicNativeInstrumentation` in configuration. | ||
# Collect code coverage using command line | ||
|
||
```shell | ||
git clone https://github.com/microsoft/codecoverage.git | ||
cd codecoverage/samples/Algorithms/tests/Algorithms.Core.Tests/ | ||
dotnet build | ||
dotnet tool install -g dotnet-coverage | ||
dotnet-coverage collect --output report.cobertura.xml --output-format cobertura "dotnet run --no-build" | ||
``` | ||
|
||
You can also use [run.ps1](run.ps1) to collect code coverage. | ||
|
||
# Collect code coverage inside github workflow | ||
|
||
`reportgenerator` can be used to generate final github summary markdown. | ||
|
||
```yml | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Test | ||
run: dotnet-coverage collect --output $GITHUB_WORKSPACE/report.cobertura.xml --output-format cobertura "dotnet run --no-build" | ||
- name: ReportGenerator | ||
uses: danielpalme/[email protected] | ||
with: | ||
reports: '${{ github.workspace }}/report.cobertura.xml' | ||
targetdir: '${{ github.workspace }}/coveragereport' | ||
reporttypes: 'MarkdownSummaryGithub' | ||
- name: Upload coverage into summary | ||
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: code-coverage-report | ||
path: ${{ github.workspace }}/report.cobertura.xml | ||
``` | ||
[Full source example](../../../../.github/workflows/Algorithms_Scenario04.yml) | ||
[Run example](../../../../../../actions/workflows/Algorithms_Scenario04.yml) | ||
# Collect code coverage inside Azure DevOps Pipelines | ||
```yml | ||
steps: | ||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'restore' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'restore' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'build' | ||
arguments: '--no-restore --configuration $(buildConfiguration)' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'build' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'custom' | ||
custom: "tool" | ||
arguments: 'install -g dotnet-coverage' | ||
displayName: 'install dotnet-coverage' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage collect --output-format cobertura --output $(Agent.TempDirectory)/report.cobertura.xml "dotnet run --project $(projectPath) --no-build --report-trx --configuration $(buildConfiguration) --results-directory $(Agent.TempDirectory)"' | ||
displayName: 'test' | ||
|
||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFormat: 'VSTest' | ||
testResultsFiles: '$(Agent.TempDirectory)/**/*.trx' | ||
publishRunAttachments: false | ||
|
||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: $(Agent.TempDirectory)/**/*.cobertura.xml | ||
``` | ||
[Full source example](azure-pipelines.yml) | ||
![alt text](azure-pipelines.jpg "Code Coverage tab in Azure DevOps pipelines") | ||
# Report example | ||
![alt text](example.report.jpg "Example report") | ||
[Link](example.report.cobertura.xml) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.