全面的单元测试覆盖率注释
我们大多数人都习惯使用 Cobertura 等工具来查找单元测试代码覆盖率。
是否有任何一组注释/框架可以用来智能地通知 Cobertura 不要测试某些类/方法/分支等?
我正在使用 Maven,因此我可以使用类级别排除来排除类,但是我追求更精细的控制级别。例如,
- 忽略这个类(可以使用排除)
- 忽略这个方法(因为这个方法仅在测试上下文中使用,或者是一个简单的 getter)
- 忽略一堆类(因为这只是演示客户端)
- 有标签,例如,如果我使用集成配置文件运行代码覆盖率,那么请检查我是否覆盖了这段代码等。
Most of us are used to using things like Cobertura for finding unit test code coverage.
Are there any set of annotations/framework that I can use to intelligently inform Cobertura to not test certain classes/methods/branches etc?
I am using maven so I can use the class level excludes to exclude classes however I am after finer level of control. For example
- Ignore this class (which is possible using excludes)
- Ignore just this method (because this one is going to be used only in test context, or is a trivial getter)
- Ignore a bunch of classes (because that is just the source code of a demo client)
- Have labels, for example if I run my code coverage with Integration profile then please check if I have covered this piece of code etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,cobertura 仪器是一个完整的类,因此忽略单个方法是行不通的。正如您已经提到的,只需使用排除即可忽略整个类。此外,为了忽略一种演示客户端,这应该是 Maven 中的一个单独模块,这只需更改 coberatura-plugin 的配置即可。
As far as i know cobertura instruments a complete class so ignoring a single method wouldn't work. The whole class can be ignored by just using excludes as you already mentioned. Furthermore to ignore a kind of a demo client this should be a separate module in Maven which simplyfies this just changing the configuration for coberatura-plugin.
Cobertura 是开源的,如果您认为这将是该工具的一个很好的补充,请联系开发人员并参与其中。
Cobertura is open source, if you think this would be a great addition to the tool then contact the developers and get involved.