Skip to content

Can't produce coverage in Docker container #1367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RPM1984 opened this issue Aug 2, 2022 · 1 comment
Closed

Can't produce coverage in Docker container #1367

RPM1984 opened this issue Aug 2, 2022 · 1 comment

Comments

@RPM1984
Copy link

RPM1984 commented Aug 2, 2022

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.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
Copy link
Author

RPM1984 commented Aug 12, 2022

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

Fixed line:

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

@RPM1984 RPM1984 closed this as completed Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant