danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
https://reportgenerator.io
Apache License 2.0
2.56k stars 279 forks source link

coverlet-coverage give much higher Cyclomatic Complexity score for given Method then Visual Studio 2022 Code Metrics Results #635

Closed wzaieddev closed 9 months ago

wzaieddev commented 9 months ago

Hi, I'm Trying to generate coverage report, and i get much higher Cyclomatic Complexity score then Visual Studio 2022 Code Metrics Results Method Cyclomatic Complexity score | coverage.cobertura.report ==> 36 Method Cyclomatic Complexity score | Code Metrics Results ==> 19

what is the most reliable value that could i adopt ?

PS: I don't know if it might be relevant or not, with SonarQube i get 19, the same value as Code Metrics Results

Please find below some technical details:

NET 6 Xunit coverlet.collector => 6.0.0 coverlet.msbuild => 6.0.0 coverage report format => cobertura Attachment: coverage.cobertura.report -> cobertura report Method-SavePaymentNotifyAsync -> Method source code , method name: SavePaymentNotifyAsync Code_Metrics_Results.PNG -> Visual studio screen

Code_Metrics_Results

coverage.cobertura.report.txt

Method-SavePaymentNotifyAsync.txt

danielpalme commented 9 months ago

ReportGenerator does not calculate the metrics itself. It uses the raw values provided in the coverage file.

Here you see the value from the report generated by ReportGenerator: image

And this is the corresponding raw value from [coverage.cobertura.report.txt] (line 8205)(https://github.com/danielpalme/ReportGenerator/files/13347944/coverage.cobertura.report.txt) image

I don't see a complexity value of 36 here. I guess you are referring to CreditCardService which also has a method SavePaymentNotifyAsync() with a complexity of 36. The same method in OrdersService has a complexity of 18 (see above).

wzaieddev commented 9 months ago

Hi, Thank you for your response. I am aware that, ReportGenerator does not calculate the metrics itself, but maybe basing on your experience, are you will be able to give me an answer. I confirm that I'm referring to CreditCardService which also has a method SavePaymentNotifyAsync() with a complexity of 36 (see attached the whole class that contains the method in question "SavePaymentNotifyAsync")

Do you have some explanation ?

please find below screens from the report xml, html ReportGenerator page and the whole class

SavePaymentNotifyAsync-CreditCardService.txt

coverage.cobertura.report.txt

image

image

danielpalme commented 9 months ago

Sorry, I don't know how coverlet calculates the metric exactly.

Cyclomatic Complexity is about number of execution paths in your code. Your method contains several if/else statements. Each case is a different execution path. Your code also contains serveral ?? operators. These are also if/else conditions.