Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple test projects #404

Open
Foshkey opened this issue May 3, 2023 · 6 comments
Open

Multiple test projects #404

Foshkey opened this issue May 3, 2023 · 6 comments
Milestone

Comments

@Foshkey
Copy link

Foshkey commented May 3, 2023

Describe the bug
First of all, awesome extension. I'm looking for something similar to VS Live Testing and this might be it 馃槃 Also, apologies if I'm missing something obvious, I tried searching for this issue.

For dotnet, I managed to get this working when I add this package to just one test project:

    <PackageReference Include="coverlet.msbuild" Version="3.2.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>

But as soon as I add it to all of my test projects within the same workspace, all covered lines indicate no code coverage within all or all but one project. The lcov.info files are generated within their respective project directories, and I confirmed that they are all different.

To Reproduce
Steps to reproduce the behaviour:

  1. Create MORE THAN ONE src csproj with code
  2. Create MORE THAN ONE test csproj with tests that target the src code
  3. Follow instructions in example provided
  4. Either display coverage in a src file or set coverage gutters to watch

Expected behaviour
All respective src code lines should indicate accurate code coverage

Screenshots
None, let me know if any screenshots are helpful!

Desktop (please complete the following information):

  • OS: Windows 11
  • Extension Version 2.10.4
  • VSCode Version 1.77.3

Additional context
The logs seem to indicate that the extension is indeed picking up all of the lcov.info files (removed sensitive file paths):

[1683140467142][coverageservice]: Loading 4 file(s)
[1683140467142][coverageservice]: c:\Users\joshua.nelson\Source\{redacted}.Tests\lcov.info,c:\Users\joshua.nelson\Source\{redacted}.Tests\lcov.info,c:\Users\joshua.nelson\Source\{redacted}.Tests\lcov.info,c:\Users\joshua.nelson\Source\{redacted}.Tests\lcov.info
[1683140467143][coverageservice]: Loaded 4 data file(s)
[1683140467148][coverageservice]: Caching 100 coverage(s)
[1683140467148][coverageservice]: READY
[1683140467148][coverageservice]: RENDERING
@ryanluker
Copy link
Owner

ryanluker commented May 6, 2023

@Foshkey Thanks for submitting an issue!

You might want to look into using the multi-root workspace functionality (see link from the example project or this link to vscode's docs).

This will allow you to have multiple "folders" or projects open at one time and have the coverage be accessible across different projects.

We can triage and investigate further if it is still an issue for you afterwords.

@Foshkey
Copy link
Author

Foshkey commented May 8, 2023

Thanks for the response!

Looks like it's still an issue. To be clear, our github repo is structured like so:

root
|- src
  |- Project1
    |- Project1.csproj
  |- Project2
    |- Project2.csproj
  |- Project3
    |- Project3.csproj
  |- Project4
    |- Project4.csproj
|- tests
  |- unit
    |- Project1.Tests
      |- Project1.Tests.csproj
    |- Project2.Tests
      |- Project2.Tests.csproj
    |- Project3.Tests
      |- Project3.Tests.csproj
    |- Project4.Tests
      |- Project4.Tests.csproj

And opening the root github folder is how most devs operate their workspace.

But, I tried adding all of the src project folders and test project folders to the workspace as separate folders like you suggested, but still the same issue that code gutters indicate no code coverage when all test projects are configured to output code coverage (but still works with just one project)

@Foshkey
Copy link
Author

Foshkey commented May 17, 2023

A coworker of mine came up with the suggestion to merge the coverage results with the following test runner arguments:

/p:CollectCoverage=true /p:CoverletOutputFormat=lcov%2cjson /p:CoverletOutput=../CoverageResults/ /p:MergeWith=../CoverageResults/coverage.json -m:1

And then add the setting for coverage gutters to pick up this file:

"coverage-gutters.coverageFileNames": [
    "coverage.info",
    "lcov.info",
    "cov.xml",
    "coverage.xml",
    "jacoco.xml",
    "coverage.cobertura.xml"
  ]

And this worked for me! Might be worth adding this to the docs for when people use multiple test projects. I didn't know that merging coverage results into one file was a thing!

@ryanluker
Copy link
Owner

A coworker of mine came up with the suggestion to merge the coverage results with the following test runner arguments:

/p:CollectCoverage=true /p:CoverletOutputFormat=lcov%2cjson /p:CoverletOutput=../CoverageResults/ /p:MergeWith=../CoverageResults/coverage.json -m:1

And then add the setting for coverage gutters to pick up this file:

"coverage-gutters.coverageFileNames": [
    "coverage.info",
    "lcov.info",
    "cov.xml",
    "coverage.xml",
    "jacoco.xml",
    "coverage.cobertura.xml"
  ]

And this worked for me! Might be worth adding this to the docs for when people use multiple test projects. I didn't know that merging coverage results into one file was a thing!

Excellent, thanks for finding that fix! Definitely we should add that to the readme / docs as folks with larger projects probably run into this all the time.

@ryanluker ryanluker added this to the 2.11.0 milestone May 22, 2023
@pabloandrade-ah
Copy link

A coworker of mine came up with the suggestion to merge the coverage results with the following test runner arguments:

/p:CollectCoverage=true /p:CoverletOutputFormat=lcov%2cjson /p:CoverletOutput=../CoverageResults/ /p:MergeWith=../CoverageResults/coverage.json -m:1

And then add the setting for coverage gutters to pick up this file:

"coverage-gutters.coverageFileNames": [
    "coverage.info",
    "lcov.info",
    "cov.xml",
    "coverage.xml",
    "jacoco.xml",
    "coverage.cobertura.xml"
  ]

And this worked for me! Might be worth adding this to the docs for when people use multiple test projects. I didn't know that merging coverage results into one file was a thing!

what is the -m:1 for?

@ryanluker
Copy link
Owner

ryanluker commented Jun 5, 2023

what is the -m:1 for?

Probably related to the merging and keeping things in sequential order (based on the docs I found below).

https://github.com/coverlet-coverage/coverlet/blob/cae57328fcf29e3f8db9c3b2b46f07af09b6e216/Documentation/Examples/MSBuild/MergeWith/HowTo.md?plain=1#L12-L20

@ryanluker ryanluker modified the milestones: 2.11.0, 2.12.0 Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants