-
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 #77 from jakubch1/main
Scenario 25
- Loading branch information
Showing
9 changed files
with
669 additions
and
2 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: "Calculator Scenario 25" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario25.yml' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Calculator | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 7.0.x | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Run tests | ||
run: dotnet-coverage collect --output-format cobertura --output ./TestResults/report.cobertura.xml "dotnet test --no-build" | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.0 | ||
with: | ||
reports: '${{ github.workspace }}/samples/Calculator/TestResults/**/*.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 }}/samples/Calculator/TestResults/**/*.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
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
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,104 @@ | ||
# Scenario Description | ||
|
||
Gather code coverage for the entire solution using dotnet-coverage tool. Refer to the provided example for collecting coverage across all unit tests. The system automatically consolidates coverage reports from all test projects. Integration tests are excluded for simplification, as the server is not initiated during this process. | ||
|
||
# Collect code coverage using command line | ||
|
||
```shell | ||
git clone https://github.com/microsoft/codecoverage.git | ||
cd codecoverage/samples/Calculator | ||
dotnet build | ||
dotnet tool install -g dotnet-coverage | ||
dotnet-coverage collect -f cobertura -o report.cobertura.xml "dotnet test --no-build" | ||
``` | ||
|
||
You can also use [run.ps1](run.ps1) to collect code coverage. | ||
|
||
# Collect code coverage inside github workflow | ||
|
||
Executing tests is automatically creating `cobertura` report. Then `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: 7.0.x | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Run tests | ||
run: dotnet-coverage collect --output-format cobertura --output ./TestResults/report.cobertura.xml "dotnet test --no-build" | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.0 | ||
with: | ||
reports: '${{ github.workspace }}/samples/Calculator/TestResults/**/*.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 }}/samples/Calculator/TestResults/**/*.cobertura.xml' | ||
``` | ||
|
||
[Full source example](../../../../.github/workflows/Calculator_Scenario25.yml) | ||
|
||
[Run example](../../../../../../actions/workflows/Calculator_Scenario25.yml) | ||
|
||
# Collect code coverage inside Azure DevOps Pipelines | ||
|
||
```yml | ||
steps: | ||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'custom' | ||
custom: "tool" | ||
arguments: 'install -g dotnet-coverage' | ||
displayName: 'install dotnet-coverage' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'restore' | ||
projects: '$(solutionPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet restore' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'build' | ||
arguments: '--no-restore --configuration $(buildConfiguration)' | ||
projects: '$(solutionPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet build' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage collect -f cobertura -o $(Agent.TempDirectory)/report.cobertura.xml "dotnet test --configuration $(buildConfiguration) --no-build --logger trx --results-directory $(Agent.TempDirectory)"' | ||
workingDirectory: '$(Build.SourcesDirectory)/samples/Calculator/' | ||
displayName: 'dotnet test' | ||
|
||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFormat: 'VSTest' | ||
testResultsFiles: '$(Agent.TempDirectory)/**/*.trx' | ||
|
||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: $(Agent.TempDirectory)/report.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.
46 changes: 46 additions & 0 deletions
46
samples/Calculator/scenarios/scenario25/azure-pipelines.yml
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,46 @@ | ||
name: "Calculator Scenario 25" | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
variables: | ||
buildConfiguration: 'Debug' | ||
solutionPath: './samples/Calculator/Calculator.sln' # this is specific to example - in most cases not needed | ||
|
||
steps: | ||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'custom' | ||
custom: "tool" | ||
arguments: 'install -g dotnet-coverage' | ||
displayName: 'install dotnet-coverage' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'restore' | ||
projects: '$(solutionPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet restore' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'build' | ||
arguments: '--no-restore --configuration $(buildConfiguration)' | ||
projects: '$(solutionPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet build' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage collect -f cobertura -o $(Agent.TempDirectory)/report.cobertura.xml "dotnet test --configuration $(buildConfiguration) --no-build --logger trx --results-directory $(Agent.TempDirectory)"' | ||
workingDirectory: '$(Build.SourcesDirectory)/samples/Calculator/' | ||
displayName: 'dotnet test' | ||
|
||
- task: PublishTestResults@2 | ||
inputs: | ||
testResultsFormat: 'VSTest' | ||
testResultsFiles: '$(Agent.TempDirectory)/**/*.trx' | ||
|
||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: $(Agent.TempDirectory)/report.cobertura.xml | ||
|
Oops, something went wrong.