0

I am using Opencover and Reportgenerator to find out the code coverage of my C# project. Currently I am able to get 100% coverage for my unit test but I want to know how much code has been covered by unit test file (I think there is a way in opencover)?

Say my unit test covers only 50% of my script, then I want opencover to report that.

I am using the following command on .bat file to run opencover and reportgenerator (I tried all possible parameters on opencover but failed to get what I needed)

"..\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -target:"..\packages\nunit.consolerunner\3.8.0\tools\nunit3-console.exe" -targetargs:".\bin\Debug\UserAuthUnitTest.dll" -register:path64 -mergebyhash -nodefaultfilters -oldstyle -showunvisited -log:verbose -filter:+[*]* -safemode:no -output:"CodeCoverageResult.xml"
"..\packages\ReportGenerator.3.1.2\tools\ReportGenerator.exe" "-reports:CodeCoverageResult.xml" "-reporttypes:Badges;HtmlSummary" "-verbosity:Verbose" "-targetdir:CodeCoverageReport"

and I am currently getting following: output on reportgenerator

Krishna Prasad S
  • 141
  • 2
  • 17

1 Answers1

0

Have a look at the xml file that OpenCover produces. It will provide a reason why it skipped your assembly.

Male sure your assembly produces a pdb file (full) and that it is in the same folder as the assembly.

Use the filters to ignore assemblies (see wiki)

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • Hi @shaun_a_wilde, thanks for responding. I checked the xml file that was generated by opencover, but I don't see any reference to the project which is being tested by these unit tests. Should something be changed in csproj file or somewhere in the project for opencover? i tried both with MSTest and NUnit, also tried AxoCover(which internally uses OpenCover) but ended up getting same results – Krishna Prasad S Mar 07 '18 at 12:14
  • Without seeing the project in question it is not really possible to tell. If your target assembly is not being loaded then is your test actually calling any classes inside it? – Shaun Wilde Mar 07 '18 at 12:30
  • My solution had multiple projects, I tried opencover with other projects within same solution and got required output. Later, I did add the project which had issue, and even that reported required results. Thanks @shaun_a_wilde for your responses. I was even able to do all these with sonarqube's opencover extension. – Krishna Prasad S Mar 08 '18 at 19:39
  • Well, later I tried using opensource AxoCover extension in my project. With this i was able to get proper code coverage percentage. – Krishna Prasad S Nov 18 '19 at 13:04