From bd3b092bc314b0eb24d15d7a4ef7ca1715a5f9c8 Mon Sep 17 00:00:00 2001 From: monaullah Date: Mon, 4 Nov 2024 22:38:24 +0100 Subject: [PATCH 1/6] wip coverlet collector --- PatternService/Pattern.cs | 4 +++ .../PatternServiceTests.csproj | 36 +++++++++++++++++++ PatternServiceTests/UnitTest1.cs | 10 ++++++ coverage.runsettings | 25 +++++++++++++ pattern-service.sln | 6 ++++ 5 files changed, 81 insertions(+) create mode 100644 PatternService/Pattern.cs create mode 100644 PatternServiceTests/PatternServiceTests.csproj create mode 100644 PatternServiceTests/UnitTest1.cs create mode 100644 coverage.runsettings diff --git a/PatternService/Pattern.cs b/PatternService/Pattern.cs new file mode 100644 index 0000000..5584617 --- /dev/null +++ b/PatternService/Pattern.cs @@ -0,0 +1,4 @@ +record Pattern(string Value) +{ + public string SomeMethod => Value; +} diff --git a/PatternServiceTests/PatternServiceTests.csproj b/PatternServiceTests/PatternServiceTests.csproj new file mode 100644 index 0000000..721c071 --- /dev/null +++ b/PatternServiceTests/PatternServiceTests.csproj @@ -0,0 +1,36 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + true + ../TestResults/coverage/ + cobertura + 100 + method + Total + + + diff --git a/PatternServiceTests/UnitTest1.cs b/PatternServiceTests/UnitTest1.cs new file mode 100644 index 0000000..add6a84 --- /dev/null +++ b/PatternServiceTests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace PatternServiceTests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + + } +} \ No newline at end of file diff --git a/coverage.runsettings b/coverage.runsettings new file mode 100644 index 0000000..98d3f68 --- /dev/null +++ b/coverage.runsettings @@ -0,0 +1,25 @@ + + + + + + + + + + .*PatternService.* + + + + ^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$ + .*Test.* + + + + + + + + + + \ No newline at end of file diff --git a/pattern-service.sln b/pattern-service.sln index db5d60a..ba2c341 100644 --- a/pattern-service.sln +++ b/pattern-service.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.002.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PatternService", "PatternService\PatternService.csproj", "{7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatternServiceTests", "PatternServiceTests\PatternServiceTests.csproj", "{3026BA50-F64E-42EB-88C9-6246E0A3E121}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}.Debug|Any CPU.Build.0 = Debug|Any CPU {7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}.Release|Any CPU.ActiveCfg = Release|Any CPU {7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}.Release|Any CPU.Build.0 = Release|Any CPU + {3026BA50-F64E-42EB-88C9-6246E0A3E121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3026BA50-F64E-42EB-88C9-6246E0A3E121}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3026BA50-F64E-42EB-88C9-6246E0A3E121}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3026BA50-F64E-42EB-88C9-6246E0A3E121}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 42a9dddbb1f6cb5be3f42ee6773cffa47ecdae8c Mon Sep 17 00:00:00 2001 From: monaullah Date: Mon, 4 Nov 2024 22:42:30 +0100 Subject: [PATCH 2/6] Upload coverage report in workflow --- .github/workflows/dotnet.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 217f7cb..57c8ad5 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -26,3 +26,16 @@ jobs: run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal + - name: Run tests with coverage + run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=../TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total + + - name: Report code coverage + run: | + dotnet tool install --global dotnet-reportgenerator-globaltool + ~/.dotnet/tools/reportgenerator -reports:../TestResults/coverage/coverage.cobertura.xml -targetdir:coveragereport + + - name: Upload coverage report + uses: actions/upload-artifact@v2 + with: + name: coverage-report + path: coveragereport From 7b1f86c61d4d26c15a3377e3570f0bbd3a0f21a9 Mon Sep 17 00:00:00 2001 From: monaullah Date: Mon, 4 Nov 2024 22:44:51 +0100 Subject: [PATCH 3/6] Update upload step using v3 --- .github/workflows/dotnet.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 57c8ad5..a7e4793 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -26,6 +26,7 @@ jobs: run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal + - name: Run tests with coverage run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=../TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total @@ -35,7 +36,7 @@ jobs: ~/.dotnet/tools/reportgenerator -reports:../TestResults/coverage/coverage.cobertura.xml -targetdir:coveragereport - name: Upload coverage report - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: coverage-report path: coveragereport From 710e6d1ee7670f269a02d25ca14d4ccc578c38dd Mon Sep 17 00:00:00 2001 From: monaullah Date: Mon, 4 Nov 2024 22:47:58 +0100 Subject: [PATCH 4/6] Fix path --- .github/workflows/dotnet.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a7e4793..8e5377f 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -28,12 +28,15 @@ jobs: run: dotnet test --no-build --verbosity normal - name: Run tests with coverage - run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=../TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total + run: | + mkdir -p TestResults/coverage + dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total - name: Report code coverage run: | dotnet tool install --global dotnet-reportgenerator-globaltool - ~/.dotnet/tools/reportgenerator -reports:../TestResults/coverage/coverage.cobertura.xml -targetdir:coveragereport + ~/.dotnet/tools/reportgenerator -reports:TestResults/coverage/coverage.cobertura.xml -targetdir:coveragereport + - name: Upload coverage report uses: actions/upload-artifact@v3 From 80c7ad48c69aeddb20cad3d6f35d6c37ec3ebe34 Mon Sep 17 00:00:00 2001 From: monaullah Date: Mon, 4 Nov 2024 22:49:34 +0100 Subject: [PATCH 5/6] Remove report step --- .github/workflows/dotnet.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 8e5377f..ac489de 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -30,16 +30,5 @@ jobs: - name: Run tests with coverage run: | mkdir -p TestResults/coverage - dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total - - - name: Report code coverage - run: | - dotnet tool install --global dotnet-reportgenerator-globaltool - ~/.dotnet/tools/reportgenerator -reports:TestResults/coverage/coverage.cobertura.xml -targetdir:coveragereport - - - - name: Upload coverage report - uses: actions/upload-artifact@v3 - with: - name: coverage-report - path: coveragereport + dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total + \ No newline at end of file From abfa37915aadb362d59d7566e6a6a71b469df223 Mon Sep 17 00:00:00 2001 From: monaullah Date: Mon, 4 Nov 2024 22:52:13 +0100 Subject: [PATCH 6/6] Merge coverage and test step --- .github/workflows/dotnet.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ac489de..7434b36 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -25,10 +25,4 @@ jobs: - name: Build run: dotnet build --no-restore - name: Test - run: dotnet test --no-build --verbosity normal - - - name: Run tests with coverage - run: | - mkdir -p TestResults/coverage - dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=TestResults/coverage/ /p:Threshold=100 /p:ThresholdType=method /p:ThresholdStat=Total - \ No newline at end of file + run: dotnet test --no-build --verbosity normal --settings coverage.runsettings \ No newline at end of file