Measure unit code coverage % for function/method on Cyclomatic Complexity?

Deadly 提交于 2019-12-11 10:35:50

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/14648966/measure-unit-code-coverage-for-function-method-on-cyclomatic-complexity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!