Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage collection & reporting #115

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.1.22",
"commands": [
"reportgenerator"
]
}
}
}
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ indent_size = 2
[*.{sln}]
indent_style = tab

[*.{json,yml}]
[*.{json,yml,xml,runsettings}]
indent_size = 2

[*.{cs,tt}]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,4 @@ __pycache__/

temp/
tmp/
etc/coverage/
7 changes: 7 additions & 0 deletions NCrontab.Tests/.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat Code Coverage" />
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
4 changes: 4 additions & 0 deletions NCrontab.Tests/NCrontab.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down
6 changes: 5 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ build_script:
$id = ([datetimeoffset]$env:APPVEYOR_REPO_COMMIT_TIMESTAMP).ToUniversalTime().ToString('yyyyMMdd''t''HHmm')
if ($isWindows) { .\pack.cmd ci-$id }
test_script:
- cmd: test.cmd
- cmd: |
call test.cmd
curl -OsSL https://uploader.codecov.io/latest/windows/codecov.exe
codecov
- sh: ./test.sh
for:
-
Expand All @@ -44,6 +47,7 @@ for:
- image: Visual Studio 2022
artifacts:
- path: dist\*.nupkg
- path: etc\coverage
deploy:
- provider: NuGet
server: https://www.myget.org/F/raboof/api/v2/package
Expand Down
20 changes: 8 additions & 12 deletions test.cmd
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
@echo off
pushd "%~dp0"
call :main %*
popd
goto :EOF

:main
call build ^
&& call :test Debug -p:CollectCoverage=true ^
-p:CoverletOutputFormat=opencover ^
-p:Exclude=[NUnit*]* ^
&& call :test Release
goto :EOF
dotnet tool restore ^
&& call build ^
&& call :test Debug ^
&& call :test Release ^
&& dotnet reportgenerator -reports:NCrontab.Tests\TestResults\*\coverage.cobertura.xml -targetdir:etc\coverage -reporttypes:TextSummary;Html ^
&& type etc\coverage\Summary.txt
popd && exit /b %ERRORLEVEL%

:test
dotnet test --no-build -c %1 NCrontab.Tests
dotnet test --no-build -s NCrontab.Tests\.runsettings -c %*
goto :EOF
17 changes: 10 additions & 7 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")"
dotnet tool restore
./build.sh
for f in net7.0 net6.0; do {
dotnet test --no-build NCrontab.Tests -c Debug -f $f \
-p:CollectCoverage=true \
-p:CoverletOutputFormat=opencover \
-p:Exclude=[NUnit*]*
dotnet test --no-build NCrontab.Tests -c Release -f $f
}
for f in net7.0 net6.0; do
for c in Debug Release; do
dotnet test --no-build -c $c -f $f \
-s NCrontab.Tests/.runsettings
done
done
dotnet reportgenerator '-reports:NCrontab.Tests/TestResults/*/coverage.cobertura.xml' \
-targetdir:etc/coverage \
'-reporttypes:TextSummary;Html'
cat etc/coverage/Summary.txt