0

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 :)

RPM1984
  • 72,246
  • 58
  • 225
  • 350
  • when I ran the same cmd `dotnet test TestProject1.dll --collect:"XPlat Code Coverage"` outside docker, I also get same error. so I guess the problem is not with container but the command itself. AFAIK the cmd `collect:"XPlat Code Coverage"` only works for project file not for dlls. – CodingMytra Aug 07 '22 at 08:40
  • @CodingMytra i ran the command outside the container on the DLL, works fine. so it's a container / linux / docker problem, with the command, not the command itself. – RPM1984 Aug 07 '22 at 23:02
  • my bad, I tried after publish and it worked. and for docker it worked by just putting `--collect:XPlat Code Coverage` without any \" character – CodingMytra Aug 10 '22 at 04:31
  • @CodingMytra OMG.. that worked. I can't believe i didn't try that. I figured because it's a string with spaces, it needed the quotes, like it did outside the container. Chuck up an answer, and il give you some rep :) Thanks again!!! – RPM1984 Aug 11 '22 at 05:28
  • 1
    see the answer below – CodingMytra Aug 11 '22 at 05:32

1 Answers1

1

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

ENTRYPOINT ["dotnet", "test", "MyAPI.Handlers.Tests.dll", "--collect:XPlat Code Coverage"]
CodingMytra
  • 2,234
  • 1
  • 9
  • 21