-
|
When I look at the coverage report generated from our C# code, I noticed that all potential "hot spots" in the code as identified by high CRAP score and Cyclomatic complexity, are actually without exception extremely simple methods that consist of a single switch expression body. In fact they're almost equivalent to dictionary lookup mappings. In fact these methods are so incredibly simple that I let an LLM generate the tests for them, to get them out of my coverage hot spots. These methods don't need any understanding of the code, it's just obviously value A goes in value Foo comes out, or value A goes in, method Foo is called with A.X and A.Y. My question is: Is the cyclomatic complexity of these methods actually that high (I guess it is, since there are many branches), and if it's really so high is cyclomatic complexity even a useful metric? Is there another metric that's more useful to identify where to add tests? EDIT: I read about this somewhat more, and I noticed that a reason for the usefulness of cyclomatic complexity is that it indicates the number of test cases necessary to achieve branch coverage. In this aspect it's completely accurate. The number of test cases to add for these methods is technically very high. The fact that it's implemented as a single extremely simple XUnit Theory that is run for a large number of different inputs and outputs is beyond the scope of the coverage reporting. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
coverlet uses ReportGenerator for the coverage reports and the metrics comes with it. Your observation is correct and there is another metric which might be interesting: {Cognitive Complexity} a new way of measuring understandability |
Beta Was this translation helpful? Give feedback.
coverlet uses ReportGenerator for the coverage reports and the metrics comes with it.
Your observation is correct and there is another metric which might be interesting: {Cognitive Complexity} a new way of measuring understandability