问题描述
是否有一种方法可以基于方法/功能级别上的复杂度"(Cyclomatic Complexity)等复杂性比率来收集/报告单元测试覆盖率?
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?
原因/意图是提供一个可度量的度量标准,以显示基于复杂性而具有较高缺陷机会的任何区域实际上具有适当的单元测试覆盖率(即,度量值超出"100%"或"80%"的覆盖率)例如,将指标更改为环复杂性的100%> = 10".
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).
我的用例当前是Java/junit,并且达到相同目的的另一种方法也将有所帮助(不一定是基于Cyclomatic的方法/函数,而是类似的测量类型).
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).
如果有一个针对Java和.NET的具有类似功能的代码覆盖工具,那将是惊人的.
if there is a code coverage tool with similar features for both java and .NET, that would be phenomenal.
谢谢!-达伦(Darren)
thanky!-Darren
推荐答案
免责声明:我是Atlassian的Clover开发人员.我看到您已经用三叶草"标记了您的问题,所以我在回答:-)
Disclaimer: I'm a Clover developer at Atlassian. I see that you've tagged your question with 'clover' so I'm answering :-)
在Clover中,您可以通过两种方式(也可以将它们组合在一起)来实现:
In Clover you can do it in two ways (also combine them):
1)您可以定义上下文过滤器,并且不对具有圈复杂度< = N的方法进行分析.请参见< clover-setup maxComplexity ="NN">
1) You can define a context filter and do not instrument methods with a cyclomatic complexity <= N. See <clover-setup maxComplexity="NN">
2)您可以定义自定义指标,例如将覆盖范围值(或更佳的未覆盖"值)乘以圈复杂度.这样的度量将显示复杂的,未发现的方法比简单的,未发现的方法更重要.参见< clover-report> /<列>
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>
哦.还有一件事. Clover会自动为您完成操作:-)在HTML报告中,您可以看到主要项目风险"指标的标签云",该指标需要覆盖率+复杂度才能显示应用程序中最潜在的关键部分.
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.
参考文献:
https://confluence.atlassian.com/display/CLOVER/clover -报告
https://confluence.atlassian.com/pages/viewpage .action?pageId = 71600304
https://confluence.atlassian.com/display/CLOVER/Treemap +图表
这篇关于是否测量关于环复杂性的功能/方法的单位代码覆盖率%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!