Is there an approach to collect/report on unit test coverage based on a complexity ratio such as Cyclomatic Complexity on a method/function level?
The reason/intent is to provide a measurable metric to show any areas that have a higher chance of defects based on complexity actually have appropriate unit test coverage (i.e. a metric away out of '100%' or '80%' coverage by changing the metric to '100% of Cyclomatic Complexity >= 10 for example).
My usecase is currently Java/junit, and a different approach to reach the same intent would also be helpful (doesn't have to be exactly method/function based on Cyclomatic, but similar type of measurement).
EDIT: if there is a code coverage tool with similar features for both java and .NET, that would be phenomenal.
thanky! -Darren
Disclaimer: I'm a Clover developer at Atlassian. I see that you've tagged your question with 'clover' so I'm answering :-)
In Clover you can do it in two ways (also combine them):
1) You can define a context filter and do not instrument methods with a cyclomatic complexity <= N. See <clover-setup maxComplexity="NN">
2) You can define your custom metric, for instance multiply coverage value (or better - the 'uncovered' value) by a cyclomatic complexity. Such metric would show complex, uncovered methods as more significant that simple, uncovered ones. See <clover-report> / <columns>
Oh. One more thing. Clover automatically does it for you :-) In the HTML report you can see a "tag cloud" of Top Project Risks metrics which takes coverage+complexity to show the most potentially critical parts of the application.
References:
https://confluence.atlassian.com/display/CLOVER/clover-setup
https://confluence.atlassian.com/display/CLOVER/clover-report
https://confluence.atlassian.com/pages/viewpage.action?pageId=71600304
https://confluence.atlassian.com/display/CLOVER/Treemap+Charts