Skip to content

CD pipeline, running against dlls and coverage generation on a different machine to the build machine #1364

@danpowell88

Description

@danpowell88

I'm trying to setup a CI/CD pipeline where we reduce the number of builds we do and just run our unit tests agains the built source, potentially on a different machine to the machine that built the dll itself (and almost definitely in a different checkout directory).

So

Machine #1 (working directory c:\build{GUID})

dotnet restore
dotnet build MySolution.sln
dotnet publish UnitTests/UnitTest.csproj -o output/tests/unittests

/output/tests/unittests is then published as a build artifact

I've also included the dotnet reproducible builds package (and building using TeamCity)

Machine 2 (working directory c:\build{GUID2})
Copy build artifacts to /output/tests/Api.UnitTests

dotnet test output/tests/Api.UnitTests/UnitTests.dll --logger:TeamCity --collect:"XPlat Code Coverage" --ResultsDirectory:output/results/tests -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura`

The tests run correctly however no coverage is output for them. I did notice that the CoverletSourceRootsMapping is not copied into the output when I do a dotnet publish, I have added a step to manually copy this into the publish directory and I can see the coverage then works, but only if the test coverage is run on the same machine that the build ran on.

What am I missing here, should I give up and just revert back to building everything and running the coverage all together ?

Activity

petli

petli commented on Jul 25, 2022

@petli
Collaborator

Hi @danpowell88, coverlet relies on finding the source code files to determine what modules to instrument. Without the source code in the exact same path on the machine running the tests coverlet will consider all the modules to be third-party packages and skip them. #1164 discuss a parameter to give the user control over this, and #1360 implements a variation of that idea to workaround this issue.

So right now you would have to build and execute the tests in one go, but keep an eye on those issues for a fix.

MarcoRossignoli

MarcoRossignoli commented on Aug 25, 2022

@MarcoRossignoli
Collaborator

@petli is right, you could dogfood the nightly build and test that feature for us also https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @danpowell88@Bertk@petli@MarcoRossignoli

        Issue actions

          CD pipeline, running against dlls and coverage generation on a different machine to the build machine · Issue #1364 · coverlet-coverage/coverlet