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.