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’ll 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 · 8 comments
Open

Multiple test projects #404

Foshkey opened this issue May 3, 2023 · 8 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
@valters-tomsons
Copy link

valters-tomsons commented Aug 15, 2024

I am facing the same issue with an identical solution/project structure as OP. Projects I'm working on use VSTest integration for coverage, not MSBuild, so report merging is not an option.

Judging from extension logs, the coverage files get detected correctly, but the extension only recognizes the first project's report.

[1723717634376][coverageservice]: Loading 3 file(s)
[1723717634376][coverageservice]: /Users/user/Source/SolutionFolder/Tests/TestProject1/TestResults/98df3ba7-86cd-4cf2-9ea7-0e4096be583c/coverage.cobertura.xml,/Users/user/Source/SolutionFolder/Tests/TestProject2/TestResults/d9c8138a-11d8-4da1-aeb3-337590014f57/coverage.cobertura.xml,/Users/user/Source/SolutionFolder/Tests/TestProject3/TestResults/af06b42e-9bec-4722-81a9-af5fdfd17f8f/coverage.cobertura.xml
[1723717634378][coverageservice]: Loaded 3 data file(s)
[1723717634437][coverageservice]: Caching 115 coverage(s)
[1723717634437][coverageservice]: READY
[1723717634437][coverageservice]: RENDERING

(solution & project path names changed)

Note: As a workaround, you can delete TestResults for all projects and run the coverage collection on a single project at a time. Makes the extension usable, but obviously suboptimal.

@ryanluker
Copy link
Owner

I am facing the same issue with an identical solution/project structure as OP. Projects I'm working on use VSTest integration for coverage, not MSBuild, so report merging is not an option.

Judging from extension logs, the coverage files get detected correctly, but the extension only recognizes the first project's report.

[1723717634376][coverageservice]: Loading 3 file(s)
[1723717634376][coverageservice]: /Users/user/Source/SolutionFolder/Tests/TestProject1/TestResults/98df3ba7-86cd-4cf2-9ea7-0e4096be583c/coverage.cobertura.xml,/Users/user/Source/SolutionFolder/Tests/TestProject2/TestResults/d9c8138a-11d8-4da1-aeb3-337590014f57/coverage.cobertura.xml,/Users/user/Source/SolutionFolder/Tests/TestProject3/TestResults/af06b42e-9bec-4722-81a9-af5fdfd17f8f/coverage.cobertura.xml
[1723717634378][coverageservice]: Loaded 3 data file(s)
[1723717634437][coverageservice]: Caching 115 coverage(s)
[1723717634437][coverageservice]: READY
[1723717634437][coverageservice]: RENDERING

(solution & project path names changed)

Note: As a workaround, you can delete TestResults for all projects and run the coverage collection on a single project at a time. Makes the extension usable, but obviously suboptimal.

Hmm the extension should find all the coverage reports within the open directory, are you able to open the project at a higher folder levels, so the extension can see the other reports?

The example project in the repo has the by default if you need an example.
https://github.com/ryanluker/vscode-coverage-gutters/tree/master/example

@ryanluker ryanluker modified the milestones: 2.12.0, 2.13.0 Oct 19, 2024
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

4 participants