Search code examples
dockercoverlet

Can't produce coverage in Docker container


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.Sdk v17.2.0 (latest), and coverlet.collector v3.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, then dotnet test with coverage)
  • I've listed the files in the directory in the container, and confirmed the coverlet DLL's are there

Any suggestions would be great! Thanks in advance :)


Solution

  • I tried by removing \" from argument and it worked.

    ENTRYPOINT ["dotnet", "test", "MyAPI.Handlers.Tests.dll", "--collect:XPlat Code Coverage"]