-
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 #68 from jakubch1/main
Scenarios 22 and 23
- Loading branch information
Showing
24 changed files
with
550 additions
and
18 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,53 @@ | ||
# 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 22" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario22.yml', 'samples/Calculator/scenarios/scenario22/coverage.runsettings' ] | ||
|
||
env: | ||
STATIC_INSTRUMENTATION_DIR: "${{ github.workspace }}/samples/Calculator/src/Calculator.Console" | ||
|
||
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/scenario22/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/ReportGenerator-GitHub-Action@5.1.24 | ||
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,53 @@ | ||
# 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 23" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario23.yml', 'samples/Calculator/scenarios/scenario23/coverage.runsettings' ] | ||
|
||
env: | ||
STATIC_INSTRUMENTATION_DIR: "${{ github.workspace }}/samples/Calculator/src/Calculator.Console" | ||
|
||
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/scenario23/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/ReportGenerator-GitHub-Action@5.1.24 | ||
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
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,138 @@ | ||
# Scenario Description | ||
|
||
This example shows that code coverage by default is collecting code coverage also for all child processes. `Calculator.Console.Tests` run tests by spawning `Calculator.Console` as child process. Static instrumentation is used here, which requres specifying what files should be instrumented by `ModulePaths.IncludeDirectories` inside runsettings. Setting `EnableStaticManagedInstrumentationRestore` to `False` means our system will not restore instrumented binaries after the run. Default format is binary (`.coverage` extension) which can be opened in Visual Studio Enterprise. | ||
|
||
# Configuration | ||
|
||
```xml | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<DataCollectionRunSettings> | ||
<DataCollectors> | ||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Configuration> | ||
<CodeCoverage> | ||
<EnableDynamicManagedInstrumentation>False</EnableDynamicManagedInstrumentation> | ||
<EnableStaticManagedInstrumentation>True</EnableStaticManagedInstrumentation> | ||
<EnableStaticManagedInstrumentationRestore>False</EnableStaticManagedInstrumentationRestore> | ||
<ModulePaths> | ||
<IncludeDirectories> | ||
<Directory Recursive="true">%STATIC_INSTRUMENTATION_DIR%</Directory> | ||
</IncludeDirectories> | ||
</ModulePaths> | ||
</CodeCoverage> | ||
</Configuration> | ||
</DataCollector> | ||
</DataCollectors> | ||
</DataCollectionRunSettings> | ||
</RunSettings> | ||
``` | ||
|
||
# Collect code coverage using command line | ||
|
||
```shell | ||
git clone https://github.com/microsoft/codecoverage.git | ||
cd codecoverage/samples/Calculator/src/Calculator.Console/ | ||
dotnet build | ||
export STATIC_INSTRUMENTATION_DIR=`pwd` | ||
cd ../../tests/Calculator.Console.Tests/ | ||
dotnet test --settings ../../scenarios/scenario22/coverage.runsettings | ||
``` | ||
|
||
> **_NOTE:_** You don't have to use `--collect "Code Coverage"` when you specify runsettings with code coverage configuration. | ||
You can also use [run.ps1](run.ps1) to collect code coverage. | ||
|
||
# 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: 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/scenario22/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/ReportGenerator-GitHub-Action@5.1.24 | ||
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 | ||
``` | ||
[Full source example](../../../../.github/workflows/Calculator_Scenario22.yml) | ||
[Run example](../../../../../../actions/workflows/Calculator_Scenario22.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: 'restore' | ||
projects: '$(testProjectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet restore (tests)' | ||
|
||
- 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: 'build' | ||
arguments: '--no-restore --configuration $(buildConfiguration)' | ||
projects: '$(testProjectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet build (tests)' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'test' | ||
arguments: '--no-build --configuration $(buildConfiguration) --settings samples/Calculator/scenarios/scenario22/coverage.runsettings' | ||
projects: '$(testProjectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet test' | ||
env: | ||
STATIC_INSTRUMENTATION_DIR: '$(Build.SourcesDirectory)/samples/Calculator/src/Calculator.Console' | ||
``` | ||
> **_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.coverage) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
samples/Calculator/scenarios/scenario22/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,45 @@ | ||
name: "Calculator Scenario 22" | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
variables: | ||
buildConfiguration: 'Debug' | ||
testProjectPath: './samples/Calculator/tests/Calculator.Console.Tests/Calculator.Console.Tests.csproj' # this is specific to example - in most cases not needed | ||
projectPath: './samples/Calculator/src/Calculator.Console/Calculator.Console.csproj' # this is specific to example - in most cases not needed | ||
|
||
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: 'restore' | ||
projects: '$(testProjectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet restore (tests)' | ||
|
||
- 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: 'build' | ||
arguments: '--no-restore --configuration $(buildConfiguration)' | ||
projects: '$(testProjectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet build (tests)' | ||
|
||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: 'test' | ||
arguments: '--no-build --configuration $(buildConfiguration) --settings samples/Calculator/scenarios/scenario22/coverage.runsettings' | ||
projects: '$(testProjectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet test' | ||
env: | ||
STATIC_INSTRUMENTATION_DIR: '$(Build.SourcesDirectory)/samples/Calculator/src/Calculator.Console' |
21 changes: 21 additions & 0 deletions
21
samples/Calculator/scenarios/scenario22/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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<DataCollectionRunSettings> | ||
<DataCollectors> | ||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Configuration> | ||
<CodeCoverage> | ||
<EnableDynamicManagedInstrumentation>False</EnableDynamicManagedInstrumentation> | ||
<EnableStaticManagedInstrumentation>True</EnableStaticManagedInstrumentation> | ||
<EnableStaticManagedInstrumentationRestore>False</EnableStaticManagedInstrumentationRestore> | ||
<ModulePaths> | ||
<IncludeDirectories> | ||
<Directory Recursive="true">%STATIC_INSTRUMENTATION_DIR%</Directory> | ||
</IncludeDirectories> | ||
</ModulePaths> | ||
</CodeCoverage> | ||
</Configuration> | ||
</DataCollector> | ||
</DataCollectors> | ||
</DataCollectionRunSettings> | ||
</RunSettings> |
Binary file not shown.
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,5 @@ | ||
cd $PSScriptRoot/../../src/Calculator.Console | ||
dotnet build | ||
$env:STATIC_INSTRUMENTATION_DIR="$PSScriptRoot/../../src/Calculator.Console" | ||
cd $PSScriptRoot/../../tests/Calculator.Console.Tests | ||
dotnet test --settings ../../scenarios/scenario22/coverage.runsettings |
Oops, something went wrong.