0

I'm using C# to develop a software which contains multiple projects in a Visual Studio solution, and I'm begin adding some unit tests.

Solution hierarchy as below, 3 projects for production code, 2 projects which only tests Project1 and Project2, respectively:


Solution
  |
  |- Project1 (100 lines)
  |- Project2 (100 lines)
  |- Project3 (100 lines)
  |
  |- Project1.UnitTests
  |- Project2.UnitTests

I followed the tutorial from Microsoft, try to get a total code coverage number of my solution and out as a text file:

dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
dotnet test --test-adapter-path:. --collect:"XPlat Code Coverage"
reportgenerator "-reports:./**/coverage.cobertura.xml" "-targetdir:Reports_Coverage" -reportTypes:TextSummary;

There was coverage in the text file, however the calculation did not put Project3 in to the formula:

  • Given that Project1, Project2, Project3 has 100 lines each, Project1, Project2 100% covered by test, Project3 is 0% (no tests)
  • The Total coverage that ReportGenerator gave me was 100% (because Project1 and Project2 both 100% covered)
  • But what I'm expecting is 67% of coverage (with Project3 in the formula)

How can I get code coverage which includes rojects that has no test covered at all?

Thanks.

YuWea
  • 165
  • 9
  • 1
    If code isn't tested, it has zero test coverage. Unless you're talking about something else, in which case you should clarify your question. – Mark Benningfield Mar 09 '23 at 13:34
  • @MarkBenningfield I've update the question to clarify my intent, thanks for the comment. – YuWea Mar 10 '23 at 01:03
  • 1
    Is there some reason you're not writing tests for project # 3? – Mark Benningfield Mar 10 '23 at 14:45
  • 1
    is project3 referenced in any of the test projects or project1 or project2 ? – CodingMytra Mar 11 '23 at 09:47
  • @CodingMytra Well, no. This is a standalone project. Will project3referenced by project1 or project2 make project3 included in the coverage calculation? Thanks for comment. – YuWea Mar 11 '23 at 13:17
  • 1
    @MarkBenningfield The owner is not writing any test (for some reason, at the moment), and I would like to reflect this fact in the coverage report. Thanks for comment. – YuWea Mar 11 '23 at 13:18
  • 1
    @YuWea, it needs to be referenced then only it will be counted for coverage. – CodingMytra Mar 11 '23 at 16:26

0 Answers0