Skip to content

Bart-Med/coverlet-coverage-repro

Repository files navigation

Option 1: Using coverlet.msbuild

Before running, uncomment the coverlet.msbuild package reference in Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj:

<PackageReference Include="coverlet.msbuild" Version="6.0.4" />

Run the following commands:

# Clean the project
dotnet clean Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configuration Debug

# Restore packages
dotnet restore Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configfile NuGet.config --verbosity Minimal /p:Configuration=Debug /p:UsePackageReference=true /p:UseExternalPackageReference=true

# Build the project
dotnet build Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configuration Debug --no-restore /p:UsePackageReference=true /p:UseExternalPackageReference=true

# Run tests with code coverage
dotnet test Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --logger trx --configuration Debug --no-restore /p:UsePackageReference=true /p:UseExternalPackageReference=true --settings coverlet.runsettings /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura

Option 2: Using coverlet.collector

Before running, uncomment the coverlet.collector package reference in Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj:

<PackageReference Include="coverlet.collector" Version="6.0.4" />

coverlet.runsettings:

<DataCollectionRunSettings>
...
</DataCollectionRunSettings>

Run the following commands:

# Clean the project
dotnet clean Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configuration Debug

# Restore packages
dotnet restore Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configfile NuGet.config --verbosity Minimal /p:Configuration=Debug /p:UsePackageReference=true /p:UseExternalPackageReference=true

# Build the project
dotnet build Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configuration Debug --no-restore /p:UsePackageReference=true /p:UseExternalPackageReference=true

# Run tests with code coverage
dotnet test Demo.Api.IntegrationTests/Demo.Api.IntegrationTests.csproj --configuration Debug --no-restore /p:UsePackageReference=true /p:UseExternalPackageReference=true --settings coverlet.runsettings --collect:"XPlat Code Coverage"

Note: Test Concurrency and Code Coverage

DemoApiIntegrationTestsStartup.cs:

[assembly: CollectionBehavior(MaxParallelThreads = 1)]

This forces tests to run sequentially, which "resolves" code coverage accuracy issues.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages