Add Code Coverage (#16)

This commit is contained in:
Deverick 2025-05-25 06:00:08 -05:00 committed by napoly
parent 7742031433
commit c1104db2d1
7 changed files with 71 additions and 8 deletions

26
.github/workflows/codacy.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: Codacy Coverage Reporter
on:
workflow_run:
workflows:
- Build and Test
types:
- completed
permissions:
contents: read
jobs:
report-coverage:
runs-on: ubuntu-latest
steps:
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: ./coverage
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1.3.0
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ./coverage/coverage.cobertura.xml

View file

@ -41,11 +41,17 @@ jobs:
run: dotnet build --no-restore
- name: Run unit tests
run: dotnet test BTCPayServer.Plugins.Monero.UnitTests --verbosity normal
run: dotnet test BTCPayServer.Plugins.Monero.UnitTests/BTCPayServer.Plugins.UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=json /p:CoverletOutput=../coverage/coverage.json
- name: Run integration tests
run: docker compose -f BTCPayServer.Plugins.IntegrationTests/docker-compose.yml run tests
- name: Cleanup Docker containers
if: always()
run: docker compose -f BTCPayServer.Plugins.IntegrationTests/docker-compose.yml down -v
run: docker compose -f BTCPayServer.Plugins.IntegrationTests/docker-compose.yml down -v
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/coverage.cobertura.xml

View file

@ -16,6 +16,14 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

View file

@ -19,6 +19,8 @@ services:
- xmr_wallet
extra_hosts:
- "tests:127.0.0.1"
volumes:
- ../coverage:/coverage
# The dev container is not used, it is just handy to run `docker-compose up dev` to start all services
dev:

View file

@ -6,4 +6,4 @@ if [ ! -z "$TEST_FILTERS" ]; then
FILTERS="--filter $TEST_FILTERS"
fi
dotnet test -c ${CONFIGURATION_NAME} $FILTERS --no-build -v n --logger "console;verbosity=normal" < /dev/null
dotnet test -c ${CONFIGURATION_NAME} $FILTERS --no-build -v n --logger "console;verbosity=normal" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=/coverage/coverage.cobertura.xml /p:MergeWith=/coverage/coverage.json< /dev/null

View file

@ -6,9 +6,19 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AssemblyName>BTCPayServer.Plugins.Monero.UnitTests</AssemblyName>
<CoverletOutput>$(MSBuildProjectDirectory)/coverage/</CoverletOutput>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
@ -23,10 +33,6 @@
<ProjectReference Include="..\btcpayserver\BTCPayServer.Abstractions\BTCPayServer.Abstractions.csproj" />
</ItemGroup>
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<!-- This will make sure that referencing BTCPayServer doesn't put any artifact in the published directory -->
<ItemDefinitionGroup>
<ProjectReference>

View file

@ -1,6 +1,8 @@
<div align="center">
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/btcpay-monero/btcpayserver-monero-plugin/dotnet.yml?branch=master)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a86461725075418b95ae501256839500)](https://app.codacy.com/gh/btcpay-monero/btcpayserver-monero-plugin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/a86461725075418b95ae501256839500)](https://app.codacy.com/gh/btcpay-monero/btcpayserver-monero-plugin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
[![Matrix rooms](https://img.shields.io/badge/%F0%9F%92%AC%20Matrix-%23btcpay--monero-blue)](https://matrix.to/#/#btcpay-monero:matrix.org)
</div>
@ -38,7 +40,20 @@ To build and run unit tests, run the following commands:
dotnet build btcpay-monero-plugin.sln
dotnet test BTCPayServer.Plugins.Monero.UnitTests --verbosity normal
```
This will build the plugin and run the unit tests.
To run unit tests with coverage, run the following command:
```bash
dotnet test BTCPayServer.Plugins.Monero.UnitTests/BTCPayServer.Plugins.UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=json /p:CoverletOutput=../coverage/coverage.json
```
To build and run integration tests, run the following commands:
```bash
dotnet build btcpay-monero-plugin.sln
docker compose -f BTCPayServer.Plugins.IntegrationTests/docker-compose.yml run tests
```
**BTCPAY_XMR_CASHCOW_WALLET_DAEMON_URI** | **Optional**. The URI of the [monero-wallet-rpc](https://getmonero.dev/interacting/monero-wallet-rpc.html) interface for the cashcow wallet. This is used to create a second wallet for testing purposes in regtest mode. | http://
If you are a developer maintaining this plugin, in order to maintain this plugin, you need to clone this repository with `--recurse-submodules`: