IntelliJ IDEA 10.5 的 Scala 案例类中的部分 EMMA 代码覆盖率
我正在使用 IntelliJ IDEA 10.5 以及 8 月 14 日更新的 Scala 插件 v0.4.1338 和 Scala 2.9.0.1。我最近开始使用 IDEA 中的 EMMA 测试覆盖率实用程序来生成覆盖率报告。
我无法确定为什么我的 Scala 案例类的构造函数行仅显示部分(黄色)覆盖。我查看了 EMMA 常见问题解答并在网上研究了这个问题,但没有成功。有谁知道如何才能达到案例类别 100% 的覆盖率?
I'm using IntelliJ IDEA 10.5 with the Scala plugin v0.4.1338 updated on August 14th, and Scala 2.9.0.1. I recently began using the EMMA test coverage utility in IDEA to generate coverage reports.
I cannot determine why the constructor line of my Scala case class is only showing partial (yellow) coverage. I have looked in the EMMA FAQs and researched the matter online with no success. Does anyone have any idea how I can reach 100% coverage on a case class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个非常古老的问题,但这个问题在某种程度上仍然存在。给定一个简单的案例类,为了从 IntelliJ 获取完整的覆盖率报告,您还需要测试
unapply
方法。如果没有它,我对这样的基本案例类别的覆盖率为 50%。
I know this is a very old question, but the problem still stands today to some extent. Given a simple case class, in order to get a full coverage report from IntelliJ you need to test the
unapply
method as well.Without it I got 50% coverage for a basic case class like that.
case class A(a: Any)
为您生成许多方法,其中:A#equals
A#canEqual
A #hashCode
A#toString
A#productPrefix
A#productElement
A#productArity
A #产品迭代器
A#copy
A.unapply
A.apply
其中大部分将在字节码中与类定义的行号相同的位置报告。
您可以编写一个反射实用程序来在案例类的每个单元测试中调用所有这些方法,修补代码覆盖工具以忽略该行,或者只是忍受它。
case class A(a: Any)
generate a number of methods for you, among them:A#equals
A#canEqual
A#hashCode
A#toString
A#productPrefix
A#productElement
A#productArity
A#productIterator
A#copy
A.unapply
A.apply
Most of these will be reported in the bytecode at the same line number as the class definition.
You could write a reflective utility to call all of these methods in each unit test for your case classes, patch the code coverage tool to ignore that line, or just put up with it.