-
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 #73 from jakubch1/main
Scenario 24
- Loading branch information
Showing
10 changed files
with
641 additions
and
4 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,43 @@ | ||
# 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 24" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario24.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: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Run tests | ||
run: dotnet test --collect "Code Coverage;Format=Cobertura" --no-build --verbosity normal --results-directory ./TestResults/ | ||
working-directory: ./samples/Calculator | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.1.26 | ||
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
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,87 @@ | ||
# Scenario Description | ||
|
||
Gather code coverage for the entire solution. 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 test --no-build --collect "Code Coverage" | ||
``` | ||
|
||
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 | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 7.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Run tests | ||
run: dotnet test --collect "Code Coverage;Format=Cobertura" --no-build --verbosity normal --results-directory ./TestResults/ | ||
working-directory: ./samples/Calculator | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.1.26 | ||
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_Scenario24.yml) | ||
[Run example](../../../../../../actions/workflows/Calculator_Scenario24.yml) | ||
# Collect code coverage inside Azure DevOps Pipelines | ||
```yml | ||
steps: | ||
- 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: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'test' | ||
arguments: '--no-build --configuration $(buildConfiguration) --collect "Code Coverage"' | ||
projects: '$(solutionPath)' # this is specific to example - in most cases not needed | ||
displayName: 'execute tests' | ||
``` | ||
> **_NOTE:_** Azure DevOps pipelines automatically recognize binary coverage report format. Code coverage results are automatically processed and published to Azure DevOps. No additional steps needed. | ||
[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.
29 changes: 29 additions & 0 deletions
29
samples/Calculator/scenarios/scenario24/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,29 @@ | ||
name: "Calculator Scenario 24" | ||
|
||
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: '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: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'test' | ||
arguments: '--no-build --configuration $(buildConfiguration) --collect "Code Coverage"' | ||
projects: '$(solutionPath)' # this is specific to example - in most cases not needed | ||
displayName: 'execute tests' |
Oops, something went wrong.