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=coberturaBefore 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"DemoApiIntegrationTestsStartup.cs:
[assembly: CollectionBehavior(MaxParallelThreads = 1)]This forces tests to run sequentially, which "resolves" code coverage accuracy issues.