-
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 #53 from jakubch1/main
Scenarios 9-12
- Loading branch information
Showing
34 changed files
with
880 additions
and
11 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,54 @@ | ||
# 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 10" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario10.yml' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Calculator/src/Calculator.Console | ||
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: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Instrument Calculator.Core.dll | ||
run: dotnet-coverage instrument --session-id TagScenario10 "./bin/Debug/net7.0/Calculator.Core.dll" | ||
- name: Instrument Calculator.Console.dll | ||
run: dotnet-coverage instrument --session-id TagScenario10 "./bin/Debug/net7.0/Calculator.Console.dll" | ||
- name: Start code coverage collection session | ||
run: dotnet-coverage collect --session-id TagScenario10 --server-mode --background -f cobertura -o $GITHUB_WORKSPACE/report.cobertura.xml | ||
- name: Run (add) | ||
run: dotnet run --no-build add 10 24 | ||
- name: Run (multiply) | ||
run: dotnet run --no-build multiply 10 24 | ||
- name: Stop code coverage collection session | ||
run: dotnet-coverage shutdown TagScenario10 | ||
- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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 11" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario11.yml', 'samples/Calculator/scenarios/scenario11/coverage.runsettings' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Calculator/tests/Calculator.Console.Tests | ||
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: Restore dependencies (Console project) | ||
run: dotnet restore ../../src/Calculator.Console/Calculator.Console.csproj | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Build (Console project) | ||
run: dotnet build --no-restore ../../src/Calculator.Console/Calculator.Console.csproj | ||
- name: Test | ||
run: dotnet test --settings ../../scenarios/scenario11/coverage.runsettings --no-build --verbosity normal | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Convert .coverage report to cobertura | ||
run: dotnet-coverage merge -r $GITHUB_WORKSPACE/samples/Calculator/tests/Calculator.Console.Tests/TestResults/*.coverage -f cobertura -o $GITHUB_WORKSPACE/report.cobertura.xml | ||
- 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: ./**/TestResults/**/*.coverage |
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,50 @@ | ||
# 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 12" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario12.yml', 'samples/Calculator/scenarios/scenario12/coverage.runsettings' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Calculator/tests/Calculator.Console.Tests | ||
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: Restore dependencies (Console project) | ||
run: dotnet restore ../../src/Calculator.Console/Calculator.Console.csproj | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Build (Console project) | ||
run: dotnet build --no-restore ../../src/Calculator.Console/Calculator.Console.csproj | ||
- name: Test | ||
run: dotnet test --settings ../../scenarios/scenario12/coverage.runsettings --no-build --verbosity normal | ||
- name: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Convert .coverage report to cobertura | ||
run: dotnet-coverage merge -r $GITHUB_WORKSPACE/samples/Calculator/tests/Calculator.Console.Tests/TestResults/*.coverage -f cobertura -o $GITHUB_WORKSPACE/report.cobertura.xml | ||
- 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: ./**/TestResults/**/*.coverage |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --collect "Code Coverage" |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --collect "Code Coverage;Format=cobertura" |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --settings ../../scenarios/scenario03/coverage.runsettings |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --collect "Code Coverage;Format=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --settings ../../scenarios/scenario05/coverage.runsettings |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --settings ../../scenarios/scenario06/coverage.runsettings |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Core.tests | ||
cd $PSScriptRoot/../../tests/Calculator.Core.Tests | ||
dotnet test --settings ../../scenarios/scenario07/coverage.runsettings |
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,143 @@ | ||
# Scenario Description | ||
|
||
This example shows how our tool [dotnet-coverage](https://aka.ms/dotnet-coverage) can be used to collect code coverage for console application using [static instrumentation](../../../../docs/instrumentation.md). `dotnet-coverage` `instrument` command is used to instrument files and code coverage session is started in background. Similar sequence can be used for more advanced scenarios - for example IIS. When executing tests this is not needed as our tooling automatically detects directory with libraries and instrument it. Cobertura report format can be used to generate HTML report using [report generator](https://github.com/danielpalme/ReportGenerator). This format can be also used with [PublishCodeCoverageResults@2](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-code-coverage-results-v2?view=azure-pipelines) in Azure DevOps pipelines. | ||
|
||
# Collect code coverage using command line | ||
|
||
```shell | ||
git clone https://github.com/microsoft/codecoverage.git | ||
cd codecoverage/samples/Calculator/src/Calculator.Console/ | ||
dotnet build | ||
dotnet tool install -g dotnet-coverage | ||
dotnet-coverage instrument --session-id TagScenario10 "./bin/Debug/net7.0/Calculator.Core.dll" | ||
dotnet-coverage instrument --session-id TagScenario10 "./bin/Debug/net7.0/Calculator.Console.dll" | ||
dotnet-coverage collect --session-id TagScenario10 --server-mode --background -f cobertura | ||
dotnet run --no-build add 10 24 | ||
dotnet run --no-build multiply 10 24 | ||
dotnet-coverage shutdown TagScenario10 | ||
``` | ||
|
||
You can also use [run.ps1](run.ps1) to execute this scenario. | ||
|
||
# Collect code coverage inside github workflow | ||
|
||
```yml | ||
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: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Instrument Calculator.Core.dll | ||
run: dotnet-coverage instrument --session-id TagScenario10 "./bin/Debug/net7.0/Calculator.Core.dll" | ||
- name: Instrument Calculator.Console.dll | ||
run: dotnet-coverage instrument --session-id TagScenario10 "./bin/Debug/net7.0/Calculator.Console.dll" | ||
- name: Start code coverage collection session | ||
run: dotnet-coverage collect --session-id TagScenario10 --server-mode --background -f cobertura -o $GITHUB_WORKSPACE/report.cobertura.xml | ||
- name: Run (add) | ||
run: dotnet run --no-build add 10 24 | ||
- name: Run (multiply) | ||
run: dotnet run --no-build multiply 10 24 | ||
- name: Stop code coverage collection session | ||
run: dotnet-coverage shutdown TagScenario10 | ||
- 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/Calculator_Scenario10.yml) | ||
[Run example](../../../../../../actions/workflows/Calculator_Scenario10.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: 'dotnet 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: 'dotnet 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 instrument --session-id TagScenario10 "$(Build.SourcesDirectory)/samples/Calculator/src/Calculator.Console/bin/Debug/net7.0/Calculator.Core.dll"' | ||
displayName: 'Instrument Calculator.Core.dll' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage instrument --session-id TagScenario10 "$(Build.SourcesDirectory)/samples/Calculator/src/Calculator.Console/bin/Debug/net7.0/Calculator.Console.dll"' | ||
displayName: 'Instrument Calculator.Console.dll' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage collect --session-id TagScenario10 --server-mode --background -f cobertura -o report.cobertura.xml' | ||
displayName: 'Start code coverage collection session' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'run' | ||
arguments: '--no-build --configuration $(buildConfiguration) add 10 24' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet run (add)' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'run' | ||
arguments: '--no-build --configuration $(buildConfiguration) multiply 10 24' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet run (multiply)' | ||
|
||
- task: Bash@3 | ||
inputs: | ||
targetType: 'inline' | ||
script: 'dotnet-coverage shutdown TagScenario10' | ||
displayName: 'Stop code coverage collection session' | ||
|
||
- task: PublishCodeCoverageResults@2 | ||
inputs: | ||
summaryFileLocation: '$(Build.SourcesDirectory)/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.
Oops, something went wrong.