coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.94k stars 386 forks source link

Can't produce coverage in Docker container #1367

Closed RPM1984 closed 1 year ago

RPM1984 commented 1 year ago

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

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:

Any suggestions would be great! Thanks in advance :)

RPM1984 commented 1 year ago

Solved. Didn't need the quotes around XPlat Code Coverage.

Fixed line:

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