Skip to content

Commit

Permalink
Scenario 3 done
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Chocholowicz committed Jan 8, 2024
1 parent e9e1052 commit 22daff7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 109 deletions.
20 changes: 8 additions & 12 deletions samples/Algorithms/scenarios/scenario03/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Collect code coverage using compile-time instrumentation for MSTest runner proje
```shell
git clone https://github.com/microsoft/codecoverage.git
cd codecoverage/samples/Algorithms/tests/Algorithms.Core.Tests/
dotnet run --ms-coverage --ms-coverage-output report.cobertura.xml --ms-coverage-output-format cobertura --ms-coverage-settings ../../scenarios/scenario02/coverage.config
dotnet build /p:MsCodeCoverageInstrumentation="true"
dotnet run --no-build --ms-coverage --ms-coverage-output report.cobertura.xml --ms-coverage-output-format cobertura
```

You can also use [run.ps1](run.ps1) to collect code coverage.
Expand All @@ -26,9 +27,9 @@ You can also use [run.ps1](run.ps1) to collect code coverage.
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore /p:MsCodeCoverageInstrumentation="true"
- name: Test
run: dotnet run --no-build --ms-coverage --ms-coverage-output $GITHUB_WORKSPACE/report.cobertura.xml --ms-coverage-output-format cobertura --ms-coverage-settings ../../scenarios/scenario02/coverage.config
run: dotnet run --no-build --ms-coverage --ms-coverage-output $GITHUB_WORKSPACE/report.cobertura.xml --ms-coverage-output-format cobertura
- name: ReportGenerator
uses: danielpalme/[email protected]
with:
Expand All @@ -44,9 +45,9 @@ You can also use [run.ps1](run.ps1) to collect code coverage.
path: ${{ github.workspace }}/report.cobertura.xml
```
[Full source example](../../../../.github/workflows/Algorithms_Scenario02.yml)
[Full source example](../../../../.github/workflows/Algorithms_Scenario03.yml)
[Run example](../../../../../../actions/workflows/Algorithms_Scenario02.yml)
[Run example](../../../../../../actions/workflows/Algorithms_Scenario03.yml)
# Collect code coverage inside Azure DevOps Pipelines
Expand All @@ -61,26 +62,21 @@ steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
arguments: '--no-restore --configuration $(buildConfiguration) /p:MsCodeCoverageInstrumentation="true"'
projects: '$(projectPath)' # this is specific to example - in most cases not needed
displayName: 'build'

- task: DotNetCoreCLI@2
inputs:
command: 'run'
arguments: '--no-build --configuration $(buildConfiguration) --results-directory $(Agent.TempDirectory) --ms-coverage --ms-coverage-output $(Agent.TempDirectory)/report.cobertura.xml --ms-coverage-output-format cobertura --report-trx'
arguments: '--no-build --configuration $(buildConfiguration) --results-directory $(Agent.TempDirectory) --ms-coverage --report-trx'
projects: '$(projectPath)' # this is specific to example - in most cases not needed
displayName: 'test'

- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '$(Agent.TempDirectory)/**/*.trx'
publishRunAttachments: false

- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: $(Agent.TempDirectory)/**/*.cobertura.xml
```
[Full source example](azure-pipelines.yml)
Expand Down
Binary file modified samples/Algorithms/scenarios/scenario03/azure-pipelines.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 54 additions & 96 deletions samples/Algorithms/scenarios/scenario03/example.report.cobertura.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<coverage line-rate="1" branch-rate="1" complexity="15" version="1.9" timestamp="1704372866" lines-covered="34" lines-valid="34" branches-covered="12" branches-valid="12">
<coverage line-rate="1" branch-rate="1" complexity="5" version="1.9" timestamp="1704439252" lines-covered="34" lines-valid="34">
<packages>
<package line-rate="1" branch-rate="1" complexity="5" name="Algorithms.Core.Tests">
<package line-rate="1" branch-rate="1" complexity="1" name="Algorithms.Core">
<classes>
<class line-rate="1" branch-rate="1" complexity="5" name="Algorithms.Core.Tests.MergerTests" filename="/home/runner/work/codecoverage/codecoverage/samples/Algorithms/tests/Algorithms.Core.Tests/MergerTests.cs">
<class line-rate="1" branch-rate="1" complexity="1" name="Algorithms.Core.Merger" filename="/home/runner/work/codecoverage/codecoverage/samples/Algorithms/src/Algorithms.Core/Merger.cs">
<methods>
<method line-rate="1" branch-rate="1" complexity="1" name="Merge" signature="(int[], int[])">
<lines>
<line number="6" hits="1" branch="False" />
<line number="7" hits="1" branch="False" />
<line number="8" hits="1" branch="False" />
<line number="9" hits="1" branch="False" />
<line number="11" hits="1" branch="False" />
<line number="13" hits="1" branch="False" />
<line number="14" hits="1" branch="False" />
<line number="15" hits="1" branch="False" />
<line number="16" hits="1" branch="False" />
<line number="18" hits="1" branch="False" />
<line number="19" hits="1" branch="False" />
<line number="21" hits="1" branch="False" />
<line number="22" hits="1" branch="False" />
<line number="24" hits="1" branch="False" />
<line number="25" hits="1" branch="False" />
<line number="27" hits="1" branch="False" />
<line number="28" hits="1" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="6" hits="1" branch="False" />
<line number="7" hits="1" branch="False" />
<line number="8" hits="1" branch="False" />
<line number="9" hits="1" branch="False" />
<line number="11" hits="1" branch="False" />
<line number="13" hits="1" branch="False" />
<line number="14" hits="1" branch="False" />
<line number="15" hits="1" branch="False" />
<line number="16" hits="1" branch="False" />
<line number="18" hits="1" branch="False" />
<line number="19" hits="1" branch="False" />
<line number="21" hits="1" branch="False" />
<line number="22" hits="1" branch="False" />
<line number="24" hits="1" branch="False" />
<line number="25" hits="1" branch="False" />
<line number="27" hits="1" branch="False" />
<line number="28" hits="1" branch="False" />
</lines>
</class>
</classes>
</package>
<package line-rate="1" branch-rate="1" complexity="4" name="Algorithms.Core.Tests">
<classes>
<class line-rate="1" branch-rate="1" complexity="4" name="Algorithms.Core.Tests.MergerTests" filename="/home/runner/work/codecoverage/codecoverage/samples/Algorithms/tests/Algorithms.Core.Tests/MergerTests.cs">
<methods>
<method line-rate="1" branch-rate="1" complexity="1" name="Test1" signature="()">
<lines>
Expand All @@ -29,15 +77,11 @@
<line number="30" hits="1" branch="False" />
</lines>
</method>
<method line-rate="1" branch-rate="1" complexity="2" name="AssertArrays" signature="(int[], int[])">
<method line-rate="1" branch-rate="1" complexity="1" name="AssertArrays" signature="(int[], int[])">
<lines>
<line number="33" hits="1" branch="False" />
<line number="34" hits="1" branch="False" />
<line number="35" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="35" hits="1" branch="False" />
<line number="36" hits="1" branch="False" />
<line number="37" hits="1" branch="False" />
</lines>
Expand All @@ -58,98 +102,12 @@
<line number="30" hits="1" branch="False" />
<line number="33" hits="1" branch="False" />
<line number="34" hits="1" branch="False" />
<line number="35" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="35" hits="1" branch="False" />
<line number="36" hits="1" branch="False" />
<line number="37" hits="1" branch="False" />
</lines>
</class>
</classes>
</package>
<package line-rate="1" branch-rate="1" complexity="10" name="Algorithms.Core">
<classes>
<class line-rate="1" branch-rate="1" complexity="10" name="Algorithms.Core.Merger" filename="/home/runner/work/codecoverage/codecoverage/samples/Algorithms/src/Algorithms.Core/Merger.cs">
<methods>
<method line-rate="1" branch-rate="1" complexity="10" name="Merge" signature="(int[], int[])">
<lines>
<line number="6" hits="1" branch="False" />
<line number="7" hits="1" branch="False" />
<line number="8" hits="1" branch="False" />
<line number="9" hits="1" branch="False" />
<line number="11" hits="1" branch="False" />
<line number="13" hits="1" branch="True" condition-coverage="100% (4/4)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
<condition number="1" type="jump" coverage="100%" />
</conditions>
</line>
<line number="14" hits="1" branch="False" />
<line number="15" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="16" hits="1" branch="False" />
<line number="18" hits="1" branch="False" />
<line number="19" hits="1" branch="False" />
<line number="21" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="22" hits="1" branch="False" />
<line number="24" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="25" hits="1" branch="False" />
<line number="27" hits="1" branch="False" />
<line number="28" hits="1" branch="False" />
</lines>
</method>
</methods>
<lines>
<line number="6" hits="1" branch="False" />
<line number="7" hits="1" branch="False" />
<line number="8" hits="1" branch="False" />
<line number="9" hits="1" branch="False" />
<line number="11" hits="1" branch="False" />
<line number="13" hits="1" branch="True" condition-coverage="100% (4/4)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
<condition number="1" type="jump" coverage="100%" />
</conditions>
</line>
<line number="14" hits="1" branch="False" />
<line number="15" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="16" hits="1" branch="False" />
<line number="18" hits="1" branch="False" />
<line number="19" hits="1" branch="False" />
<line number="21" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="22" hits="1" branch="False" />
<line number="24" hits="1" branch="True" condition-coverage="100% (2/2)">
<conditions>
<condition number="0" type="jump" coverage="100%" />
</conditions>
</line>
<line number="25" hits="1" branch="False" />
<line number="27" hits="1" branch="False" />
<line number="28" hits="1" branch="False" />
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
Binary file modified samples/Algorithms/scenarios/scenario03/example.report.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion samples/Algorithms/scenarios/scenario03/run.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cd $PSScriptRoot/../../tests/Algorithms.Core.Tests
dotnet run --ms-coverage --ms-coverage-output report.cobertura.xml --ms-coverage-output-format cobertura --ms-coverage-settings $PSScriptRoot/coverage.config
dotnet build /p:MsCodeCoverageInstrumentation="true"
dotnet run --no-build --ms-coverage --ms-coverage-output report.cobertura.xml --ms-coverage-output-format cobertura

0 comments on commit 22daff7

Please sign in to comment.