IntelliJ IDEA 10.5 的 Scala 案例类中的部分 EMMA 代码覆盖率

发布于 2024-11-29 15:33:01 字数 227 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝有风,海豚有海 2024-12-06 15:33:01

我知道这是一个非常古老的问题,但这个问题在某种程度上仍然存在。给定一个简单的案例类,为了从 IntelliJ 获取完整的覆盖率报告,您还需要测试 unapply 方法。

// Code

final case class Foo(symbol: String, name: String)

// Test

val myFoo = Foo("TheSymbol", "TheName")

Foo.unapply(myFoo).get should be(("TheSymbol", "TheName"))

如果没有它,我对这样的基本案例类别的覆盖率为 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.

// Code

final case class Foo(symbol: String, name: String)

// Test

val myFoo = Foo("TheSymbol", "TheName")

Foo.unapply(myFoo).get should be(("TheSymbol", "TheName"))

Without it I got 50% coverage for a basic case class like that.

花之痕靓丽 2024-12-06 15:33:01

case class A(a: Any) 为您生成许多方法,其中:

  1. A#equals
  2. A#canEqual
  3. A #hashCode
  4. A#toString
  5. A#productPrefix
  6. A#productElement
  7. A#productArity
  8. A #产品迭代器
  9. A#copy
  10. A.unapply
  11. A.apply

其中大部分将在字节码中与类定义的行号相同的位置报告。

您可以编写一个反射实用程序来在案例类的每个单元测试中调用所有这些方法,修补代码覆盖工具以忽略该行,或者只是忍受它。

case class A(a: Any) generate a number of methods for you, among them:

  1. A#equals
  2. A#canEqual
  3. A#hashCode
  4. A#toString
  5. A#productPrefix
  6. A#productElement
  7. A#productArity
  8. A#productIterator
  9. A#copy
  10. A.unapply
  11. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文