-
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 #57 from jakubch1/main
Scenarios 13-15
- Loading branch information
Showing
23 changed files
with
1,160 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,46 @@ | ||
# 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 13" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario13.yml' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Calculator/tests/Calculator.Server.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: Build | ||
run: dotnet build --no-restore | ||
- name: Test | ||
run: dotnet test --collect "Code Coverage" --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.Server.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 14" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario14.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: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Start server | ||
run: dotnet-coverage collect --output report.coverage --session-id TagScenario14 "dotnet run --no-build" & | ||
working-directory: ./samples/Calculator/src/Calculator.Server | ||
- name: Run tests | ||
run: dotnet test --collect "Code Coverage" --no-build --verbosity normal | ||
working-directory: ./samples/Calculator/tests/Calculator.Server.IntegrationTests | ||
- name: Stop server | ||
run: dotnet-coverage shutdown TagScenario14 | ||
- name: Merge coverage reports | ||
run: dotnet-coverage merge -r -f cobertura -o $GITHUB_WORKSPACE/report.cobertura.xml *.coverage ../../src/Calculator.Server/report.coverage | ||
working-directory: ./samples/Calculator/tests/Calculator.Server.IntegrationTests | ||
- 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: '${{ 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,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 15" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Calculator/tests/**', 'samples/Calculator/src/**', '.github/workflows/Calculator_Scenario15.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: Install dotnet-coverage | ||
run: dotnet tool install -g dotnet-coverage | ||
- name: Start code coverage collection | ||
run: dotnet-coverage collect --output-format cobertura --output $GITHUB_WORKSPACE/report.cobertura.xml --session-id TagScenario15 --background --server-mode | ||
working-directory: ./samples/Calculator/src/Calculator.Server | ||
- name: Start server | ||
run: dotnet-coverage connect --background TagScenario15 "dotnet run --no-build" | ||
working-directory: ./samples/Calculator/src/Calculator.Server | ||
- name: Run tests | ||
run: dotnet-coverage connect TagScenario15 "dotnet test --no-build" | ||
working-directory: ./samples/Calculator/tests/Calculator.Server.IntegrationTests | ||
- name: Stop server | ||
run: dotnet-coverage shutdown TagScenario15 | ||
- 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: '${{ 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
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,90 @@ | ||
# Scenario Description | ||
|
||
Collect code coverage for ASP.NET Core tests. Default format is binary (`.coverage` extension) which can be opened in Visual Studio Enterprise. | ||
|
||
# Collect code coverage using command line | ||
|
||
```shell | ||
git clone https://github.com/microsoft/codecoverage.git | ||
cd codecoverage/samples/Calculator/tests/Calculator.Server.Tests/ | ||
dotnet test --collect "Code Coverage" | ||
``` | ||
|
||
You can also use [run.ps1](run.ps1) to collect code coverage. | ||
|
||
# Collect code coverage inside github workflow | ||
|
||
To generate summary report `.coverage` report needs to be converted to `cobertura` report using `dotnet-coverage` tool. 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: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Test | ||
run: dotnet test --collect "Code Coverage" --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.Server.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_Scenario13.yml) | ||
|
||
[Run example](../../../../../../actions/workflows/Calculator_Scenario13.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: 'test' | ||
arguments: '--no-build --configuration $(buildConfiguration) --collect "Code Coverage"' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet test' | ||
``` | ||
|
||
> **_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) |
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/scenario13/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 13" | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
variables: | ||
buildConfiguration: 'Debug' | ||
projectPath: './samples/Calculator/tests/Calculator.Server.Tests/Calculator.Server.Tests.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: '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: 'test' | ||
arguments: '--no-build --configuration $(buildConfiguration) --collect "Code Coverage"' | ||
projects: '$(projectPath)' # this is specific to example - in most cases not needed | ||
displayName: 'dotnet test' |
Binary file not shown.
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,2 @@ | ||
cd $PSScriptRoot/../../tests/Calculator.Server.Tests | ||
dotnet test --collect "Code Coverage" |
Oops, something went wrong.