coverlet
coverlet copied to clipboard
Can't produce coverage in Docker container
Hi there,
I'm having trouble getting coverlet to run in my docker container. My problems seems similar to this issue, although the problem persists, and there are some differences.
Setup
- .NET 6 tests project.
- References have
Microsoft.NET.Test.Sdkv17.2.0 (latest), andcoverlet.collectorv3.1.2 (latest)
I'm running the tests in a Dockerfile, like so:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY ["src/MyAPI/", "src/MyAPI/"]
COPY ["tests/MyAPI.Handlers.Tests/", "tests/MyAPI.Handlers.Tests/"]
WORKDIR "/tests/MyAPI.Handlers.Tests"
RUN dotnet restore "MyAPI.Handlers.Tests.csproj" --configfile NuGet.config
FROM build AS publish
WORKDIR /tests/MyAPI.Handlers.Tests
RUN dotnet publish "MyAPI.Handlers.Tests.csproj" -c Release -o /tests/publish --no-restore
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS final
WORKDIR /tests
COPY --from=publish /tests/publish .
ENTRYPOINT ["dotnet", "test", "MyAPI.Handlers.Tests.dll", "--collect:\"XPlat Code Coverage\""]
So i am doing a dotnet publish, and running the tests from there. That should mean that everything is there, that needs to run the tests / coverage.
When i run, i get this error:
Data collection : Unable to find a datacollector with friendly name '"XPlat Code Coverage"'.
What i've confirmed:
- Command works outside docker fine (e.g if i do a
dotnet publish, thendotnet testwith coverage) - I've listed the files in the directory in the container, and confirmed the
coverletDLL's are there
Any suggestions would be great! Thanks in advance :)
Solved. Didn't need the quotes around XPlat Code Coverage.
Fixed line:
ENTRYPOINT ["dotnet", "test", "MyAPI.Handlers.Tests.dll", "--collect:XPlat Code Coverage"]